I'm trying to flip a sprite on the X-axis continuously at a certain delay. That is, when the game starts the enemy sprite should keep flipping until destroyed.
I first tried adding it via animator but for some weird reason FlipX via animator was not working, scale and rotation would work but FlipX would have no effect. Maybe some bug?
Then I tried adding it as a script. I did some reading here and found that it can either be done via Invoke()
or Coroutine()
. I wrote the script below from examples but it is not working. It flips the sprite at start and then stops. How do I make it flip continuously?
private bool flipState;
// Use this for initialization
void Start () {
flipState = false;
StartCoroutine("Flippy");
}
void Update()
{
}
IEnumerator Flippy()
{
while (true)
{
GetComponent<SpriteRenderer>().flipX = !flipState;
yield return new WaitForSeconds(1f);
GetComponent<SpriteRenderer>().flipX = !flipState;
}
}