Need help trying to get button to light up sprite

I’m trying to get a sprite light up to red, then back to white, picked from a random group of sprites. This should happen after I click a button, which I have assigned an on click event to run public void gameStart, with the object being an object holding all my sprites. This object has this script assigned to it and contains the array of sprites, shown in the inspector. When I click the button it doesn’t work. Help would be much appreciated, Thanks.

,I’m trying to make a random sprite go red, then back to white, from a group of sprites. I’ve assigned public void gameStart, to an onclick event on a button, with the object being the object that holds all my sprites which the script is assigned to. The sprites are all in an array in this object. But when I click the button it does nothing. Any help would be appreciated.84876-doesntworkreal.png

1 Answer

1

You should never use sleep. Your are effectively stopping execution. Use a Coroutine with a timer instead.

IEnumerator FlaaFlee()
{
	// Do your first color change
	yield return new WaitForSeconds(1f);
	// Do your second color change
}

public void gameStart()
{
	StartCoroutine(FlaaFlee());
}

Thanks for the response, I'm quite new to c#, how would I go about this?