diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-04-12 23:05:54 -0500 |
---|---|---|
committer | Neil Kollack <nkollack@gmail.com> | 2022-04-12 23:05:54 -0500 |
commit | e1d53128f8d50d01235d7ba8013f485cd47a3e83 (patch) | |
tree | d09e2d27748839d6c41d2f3a1b8bb91a79337759 /Assets/Scripts/Traps/TimedTrap.cs | |
parent | a820d2892f7c44ef4e5ddd76a6973adb38e9bfa4 (diff) |
feat: add traps
Diffstat (limited to 'Assets/Scripts/Traps/TimedTrap.cs')
-rw-r--r-- | Assets/Scripts/Traps/TimedTrap.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Assets/Scripts/Traps/TimedTrap.cs b/Assets/Scripts/Traps/TimedTrap.cs new file mode 100644 index 0000000..1cae196 --- /dev/null +++ b/Assets/Scripts/Traps/TimedTrap.cs @@ -0,0 +1,58 @@ +using System.Collections; +using UnityEngine; + +public class TimedTrap : TrapDamage +{ + [Header("TimedTrap")] + [SerializeField] protected float activationDelay; + [SerializeField] protected float activeTime; + + protected Animator animator; + protected SpriteRenderer sr; + protected bool triggered; + protected bool active; + + protected void Awake() + { + animator = GetComponent<Animator>(); + sr = GetComponent<SpriteRenderer>(); + } + + protected void Update() + { + if (!triggered) + { + StartCoroutine(Activate()); + } + } + + protected new void OnTriggerEnter2D(Collider2D collision) + { + if (active) + { + base.OnTriggerEnter2D(collision); + } + } + + protected new void OnTriggerStay2D(Collider2D collision) + { + if(active && !stay) + { + StartCoroutine(base.StayDamage(collision)); + } + } + + protected IEnumerator Activate() + { + triggered = true; + + yield return new WaitForSeconds(activationDelay); + active = true; + animator.SetBool("activated", true); + + yield return new WaitForSeconds(activeTime); + triggered = false; + active = false; + animator.SetBool("activated", false); + } +} |