Hey everyone,
Hoping this is a simple one but its got me stumped.
Im making a simple 2d games and I want my characters to blink occasionally. So I need to create a sprite animation and then have the animator wait a random amount of time and then play the blink animation.
What I’ve tried so far is making a blink animation and then created this script to play the animation however this did not work
public class WaitAndPlayAnim : MonoBehaviour {
public float randomWait;
void Start()
{
StartCoroutine ("WaitSeconds"); //wait random seconds for animation
}
IEnumerator WaitSeconds ()
{
while(true)
{
var randomWait = Random.Range(0, 6);
Debug.Log ("wait " + randomWait + " Seconds");
animation.Play("Blink");
yield return new WaitForSeconds(randomWait);
}
}
}