I have a little problem with OnTriggerStay. I have box as trigger and want to deal damage to all enemies inside that box every 1s , but only 1 of them takes damage , if 1 is killed secound one is taking damage and so forth. How to do that for all enemies inside trigger?(I dont want to use overlapsphere)
using UnityEngine;
using System.Collections;
public class FlameThrower : MonoBehaviour {
public int DamageMin;
public int DamageMax;
private float cdCounter;
public float CoolDown = 1;
public ParticleSystem Fire;
// Use this for initialization
void Start () {
Fire.enableEmission = false;
}
// Update is called once per frame
void Update () {
if (cdCounter > 0)
{
cdCounter -= Time.deltaTime;
}
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Enemy")
{
Fire.enableEmission = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.tag == "Enemy")
{
Fire.enableEmission = false;
}
}
void OnTriggerStay(Collider col)
{
Fire.enableEmission = true;
if(cdCounter <= 0)
{
col.GetComponent<Health>().health -= Random.Range(DamageMin,DamageMax);
cdCounter = CoolDown;
}
//print (col.gameObject.name);
}
}
As i noticed only last one enemy entering trigger takes damage (every 1s as i want).
Thanks in advance.