diff --git a/Assets/Enemies/Ennemy.cs b/Assets/Enemies/Ennemy.cs index d94b629..52af895 100644 --- a/Assets/Enemies/Ennemy.cs +++ b/Assets/Enemies/Ennemy.cs @@ -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().AnimateHit(); } } @@ -67,4 +70,20 @@ public class Ennemy : MonoBehaviour { _player.GetComponent().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); + } + } } diff --git a/Assets/Player/Scripts/PlayerCollisions.cs b/Assets/Player/Scripts/PlayerCollisions.cs index 77bcc60..5b4a449 100644 --- a/Assets/Player/Scripts/PlayerCollisions.cs +++ b/Assets/Player/Scripts/PlayerCollisions.cs @@ -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(); + _sr = GetComponent(); } 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); + } + } } diff --git a/Assets/Weapons/Arrow/Arrow.cs b/Assets/Weapons/Arrow/Arrow.cs index 45b9b71..07adc09 100644 --- a/Assets/Weapons/Arrow/Arrow.cs +++ b/Assets/Weapons/Arrow/Arrow.cs @@ -20,6 +20,7 @@ public class Arrow : MonoBehaviour if (collision.CompareTag("Ennemy")) { collision.gameObject.GetComponent().Life -= Damages; + collision.gameObject.GetComponent().AnimateHit(); Destroy(gameObject); } diff --git a/Assets/Weapons/Halo/Sword.cs b/Assets/Weapons/Halo/Sword.cs index dbb61d4..34dc284 100644 --- a/Assets/Weapons/Halo/Sword.cs +++ b/Assets/Weapons/Halo/Sword.cs @@ -28,6 +28,7 @@ public class Sword : MonoBehaviour if (collision.CompareTag("Ennemy") && collision.gameObject != null) { collision.GetComponent().Life -= Damages; + collision.gameObject.GetComponent().AnimateHit(); } } } diff --git a/Assets/Weapons/Laser/Laser Beam.cs b/Assets/Weapons/Laser/Laser Beam.cs index 0bc46d4..29a11a7 100644 --- a/Assets/Weapons/Laser/Laser Beam.cs +++ b/Assets/Weapons/Laser/Laser Beam.cs @@ -18,6 +18,7 @@ public class LaserBeam : MonoBehaviour if (collision.CompareTag("Ennemy")) { collision.gameObject.GetComponent().Life -= Damages; + collision.gameObject.GetComponent().AnimateHit(); } }