fixed enemies not dying if pinned

This commit is contained in:
Sam 2023-05-06 18:12:32 -07:00
parent 3ad6568707
commit dcfae28ee3
2 changed files with 22 additions and 9 deletions

View File

@ -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<BoxCollider2D>().enabled = false;
animator.Play("Explosion");
float explosionTime = .25f;
// print("explosiontime: " + explosionTime);
this.gameObject.GetComponent<AudioSource>().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<BoxCollider2D>().enabled = true;
isPlayingDefeatAnimation = false;
this.gameObject.SetActive(false);

View File

@ -72,14 +72,13 @@ public class TambourineBehavior : MonoBehaviour {
if (col.tag == "Enemy") {
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
collidedObject = col.gameObject;
print("Pinning to enemy");
// print("Pinning to enemy");
this.gameObject.GetComponent<CircleCollider2D>().enabled = false;
collidedObject.GetComponent<EnemyPatrol>().pinned = true;
collidedObject.GetComponent<EnemyPatrol>().TogglePin(true);
collidedObject.GetComponent<EnemyPatrol>().TogglePin(true, this);
} else if (col.tag == "Projectile") {
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
collidedObject = col.gameObject;
print("pinned to projectile");
// print("pinned to projectile");
this.gameObject.GetComponent<CircleCollider2D>().enabled = false;
collidedObject.GetComponent<ProjectileBehavior>().Pin();
}
@ -106,8 +105,10 @@ public class TambourineBehavior : MonoBehaviour {
}
if (collidedObject != null && collidedObject.tag == "Enemy") {
collidedObject.GetComponent<EnemyPatrol>().pinned = false;
collidedObject.GetComponent<EnemyPatrol>().TogglePin(false);
EnemyPatrol enemy = collidedObject.GetComponent<EnemyPatrol>();
if (!enemy.isPlayingDefeatAnimation) {
enemy.TogglePin(false, this);
}
} else if (collidedObject != null && collidedObject.tag == "Projectile") {
collidedObject.GetComponent<ProjectileBehavior>().Explode();
}