Play Animation (blink opacity) on hit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class Arrow : MonoBehaviour
|
||||
if (collision.CompareTag("Ennemy"))
|
||||
{
|
||||
collision.gameObject.GetComponent<Ennemy>().Life -= Damages;
|
||||
collision.gameObject.GetComponent<Ennemy>().AnimateHit();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Sword : MonoBehaviour
|
||||
if (collision.CompareTag("Ennemy") && collision.gameObject != null)
|
||||
{
|
||||
collision.GetComponent<Ennemy>().Life -= Damages;
|
||||
collision.gameObject.GetComponent<Ennemy>().AnimateHit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class LaserBeam : MonoBehaviour
|
||||
if (collision.CompareTag("Ennemy"))
|
||||
{
|
||||
collision.gameObject.GetComponent<Ennemy>().Life -= Damages;
|
||||
collision.gameObject.GetComponent<Ennemy>().AnimateHit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user