diff --git a/Assets/Scripts/EnemyPatrol.cs b/Assets/Scripts/EnemyPatrol.cs index c9cf147..f915a41 100644 --- a/Assets/Scripts/EnemyPatrol.cs +++ b/Assets/Scripts/EnemyPatrol.cs @@ -4,7 +4,9 @@ using UnityEngine; public class EnemyPatrol : MonoBehaviour { + [Header("Tambourine")] [HideInInspector] public bool pinned = false; + [HideInInspector] public TambourineBehavior pinnedTambourine; [Header("Horizontal")] public bool isHorizontal; @@ -60,13 +62,15 @@ public class EnemyPatrol : MonoBehaviour { } } - public void TogglePin(bool isPinned) { + public void TogglePin(bool isPinned, TambourineBehavior tambourine) { + this.pinned = isPinned; if (isPinned) { animator.speed = 0; + this.pinnedTambourine = tambourine; } else { animator.speed = 1; + this.pinnedTambourine = null; } - } public void DefeatEnemy() { @@ -75,10 +79,18 @@ public class EnemyPatrol : MonoBehaviour { IEnumerator Defeat() { isPlayingDefeatAnimation = true; + if (pinned) { + pinnedTambourine.DestroySelf(); + TogglePin(false, this.pinnedTambourine); + } this.gameObject.GetComponent().enabled = false; animator.Play("Explosion"); + float explosionTime = .25f; + // print("explosiontime: " + explosionTime); this.gameObject.GetComponent().Play(); - yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length); + // print("reached early point"); + yield return new WaitForSeconds(explosionTime); + // print("reached late point"); this.gameObject.GetComponent().enabled = true; isPlayingDefeatAnimation = false; this.gameObject.SetActive(false); diff --git a/Assets/Scripts/TambourineBehavior.cs b/Assets/Scripts/TambourineBehavior.cs index ac96d06..d731096 100644 --- a/Assets/Scripts/TambourineBehavior.cs +++ b/Assets/Scripts/TambourineBehavior.cs @@ -72,14 +72,13 @@ public class TambourineBehavior : MonoBehaviour { if (col.tag == "Enemy") { this.gameObject.GetComponent().enabled = false; collidedObject = col.gameObject; - print("Pinning to enemy"); + // print("Pinning to enemy"); this.gameObject.GetComponent().enabled = false; - collidedObject.GetComponent().pinned = true; - collidedObject.GetComponent().TogglePin(true); + collidedObject.GetComponent().TogglePin(true, this); } else if (col.tag == "Projectile") { this.gameObject.GetComponent().enabled = false; collidedObject = col.gameObject; - print("pinned to projectile"); + // print("pinned to projectile"); this.gameObject.GetComponent().enabled = false; collidedObject.GetComponent().Pin(); } @@ -106,8 +105,10 @@ public class TambourineBehavior : MonoBehaviour { } if (collidedObject != null && collidedObject.tag == "Enemy") { - collidedObject.GetComponent().pinned = false; - collidedObject.GetComponent().TogglePin(false); + EnemyPatrol enemy = collidedObject.GetComponent(); + if (!enemy.isPlayingDefeatAnimation) { + enemy.TogglePin(false, this); + } } else if (collidedObject != null && collidedObject.tag == "Projectile") { collidedObject.GetComponent().Explode(); }