unity update boolean from other script

by Laurenz   Last Updated October 09, 2019 07:13 AM - source

So my problem is that the color of the sprite should only change if the Boolean is true. My theory is that the Boolean isn't being update. So how do I update the Boolean the whole time and see if it is getting changed.

Thanks Guys,

 public class controlborder : MonoBehaviour
    {
        private SpriteRenderer m_spriteRenderer;
        public float loopdelay = 2f;
        public static bool startstop;
        public void Start()
        {
            m_spriteRenderer = GetComponent<SpriteRenderer>();
            StartCoroutine(Changecolor(2f));
        }
        public void Update()
        {
        }
        private IEnumerator Changecolor(float loopdelay)
        {
            while (true)
            {
                startstop = control.changecolorborder; <== this bool
                Debug.Log(startstop);

                while (startstop)
                {
                    yield return new WaitForSeconds(1F);
                    int random = Random.Range(1, 4);
                    if (random == 1)
                    {
                        m_spriteRenderer.color = Color.blue;
                    }
                    else if (random == 2)
                    {
                        m_spriteRenderer.color = Color.red;
                    }
                    else if (random == 3)
                    {
                        m_spriteRenderer.color = Color.green;
                    }
                    else
                    {
                        m_spriteRenderer.color = Color.yellow;
                    }

                }
            }
        }
    }
Tags : unity c#


Related Questions


Unfortunately game has stopped

Updated July 02, 2019 11:13 AM

How to animate objects in Unity 3D

Updated July 12, 2015 13:05 PM