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;
}
}
}
}
}