Play Animation (blink opacity) on hit

This commit is contained in:
2023-10-17 12:04:43 +02:00
parent cd37cd4522
commit 899427d70c
5 changed files with 45 additions and 1 deletions
+19
View File
@@ -1,3 +1,5 @@
using System.Collections;
using Unity.VisualScripting.FullSerializer;
using UnityEngine;
[
@@ -52,6 +54,7 @@ public class Ennemy : MonoBehaviour
if (collision.gameObject.CompareTag("Player"))
{
InvokeRepeating(nameof(AttackPlayer), 0, 1f);
_player.GetComponent<PlayerCollisions>().AnimateHit();
}
}
@@ -67,4 +70,20 @@ public class Ennemy : MonoBehaviour
{
_player.GetComponent<PlayerManager>().TakeDamage(Damages);
}
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);
}
}
}