Play Animation (blink opacity) on hit
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(PlayerManager))]
|
||||
[
|
||||
RequireComponent(typeof(PlayerManager)),
|
||||
RequireComponent(typeof(SpriteRenderer))
|
||||
]
|
||||
public class PlayerCollisions : MonoBehaviour
|
||||
{
|
||||
private PlayerManager _pm;
|
||||
private SpriteRenderer _sr;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_pm = GetComponent<PlayerManager>();
|
||||
_sr = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collision)
|
||||
@@ -37,4 +43,20 @@ public class PlayerCollisions : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AnimateHit()
|
||||
{
|
||||
StartCoroutine(IAnimateHit());
|
||||
}
|
||||
|
||||
private IEnumerator IAnimateHit()
|
||||
{
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
_sr.color = new Color(_sr.color.r, _sr.color.g, _sr.color.b, 0f);
|
||||
yield return new WaitForSeconds(.1f);
|
||||
_sr.color = new Color(_sr.color.r, _sr.color.g, _sr.color.b, 1f);
|
||||
yield return new WaitForSeconds(.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user