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.
Answer by Socapex · Dec 28, 2016 at 09:11 PM
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?
No problem. I added a quick example. This may not fix the problem, but it's a start ;)
Note that you can use the CODE snippet in your questions ins$$anonymous$$d of an image. With that, I could have copy pasted your code to make it easier. Cheers.
Your answer
Follow this Question
Related Questions
Getting name of Spritesheet on runtime with C#? (Not individual SpriteName) 1 Answer
Problem Changing Sprites with an Array of Sprites 1 Answer
Sprites being skipped over in sprite change script 1 Answer
SpriteDiffuse shader has inconsistent interaction with point/spot lights? 1 Answer
Using Gizmo Cubes as a reference for placing sprites, then deleting all Gizmos? 2 Answers