I have an enemy and I want it to have a blinking effect (when it gets hit) by changing the alpha.
I'm not doing this using animation due to some other animation already being there. So, I'm changing the alpha of the sprite using a script, but it's not working.
Here's the script:
private void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Bullet")
{
StartCoroutine("Blinker");
}
}
IEnumerator Blinker()
{
GameObject This = this.gameObject;
Color tmp = This.GetComponent<SpriteRenderer>().color;
Color tmp2 = This.GetComponent<SpriteRenderer>().color;
tmp.a = 0f;
tmp2.a = 1;
This.GetComponent<SpriteRenderer>().color = tmp;
yield return new WaitForSeconds(sec);
This.GetComponent<SpriteRenderer>().color = tmp2;
}
Here's the inspector of the object I'm changing:

Animatorcomponent anyways and see if the blinking effect works.