protected void DamageFromTrap() { if (onTraps.Count > 0 && frameCounter % 30 == 0) { HurtEffect(); } for (int i = 0; i < onTraps.Count; i++) { GameObject trap = onTraps [i]; if (trap.tag == "SpikeTrap") { health -= trap.GetComponent <Trap> ().damagePerSec *Time.deltaTime; } else if (trap.tag == "Flame") { FlameTrap trapScript = trap.gameObject.transform.parent.gameObject.GetComponent <FlameTrap> (); if (trapScript.isActive) { health -= trapScript.damagePerSec * Time.deltaTime; } } else if (trap.tag == "Laser") { LaserTrap trapScript = trap.gameObject.transform.parent.gameObject.GetComponent <LaserTrap> (); if (trapScript.isActive) { health -= trapScript.damagePerSec * Time.deltaTime; } } } }
//when instantiated, destroy the laser script after trapActiveTime void Awake() { trap = GetComponent <LaserTrap>(); lineShaderGameObject = Instantiate(trap.lineShader.gameObject); lineShader = lineShaderGameObject.GetComponent <LineShaderUtility>(); StartCoroutine(DestroyAfterTime()); source = SoundManager.SoundManagerInstance.Play(GetComponent <LaserTrap>().laserSound, Vector2.zero, GetComponent <LaserTrap>().volume, 1.0f, true, AudioGroup.Effects); }
//destroy laser protected IEnumerator DestroyAfterTime() { LaserTrap trap = gameObject.GetComponent <LaserTrap>(); if (trap) { yield return(new WaitForSeconds(trap.trapActiveTime)); Destroy(lineShaderGameObject); SoundManager.SoundManagerInstance.RemoveAudioSource(source); Destroy(this, 0); } }
// Start is called before the first frame update void Start() { laserTrap = GetComponentInParent <LaserTrap>(); }