OnTriggerStay2D does not trigger if it’s being spawned on an object which is not moving. If that object moves after the trigger has spawned it will activate the trigger.
How can I make this trigger fire on Start() if there are any enemies in it?
In my case it’s an AOE field on the ground which should damage object staying inside it:
void OnTriggerStay2D(Collider2D other)
{
float timerComparison = Time.time;
if ((timerComparison - timer) * 1000 > 250)
{
other.gameObject.GetComponent<EnemyStats>().Damage(dpsValue / 4);
timer = Time.time;
}
}
I think a coroutine always looking for objects inside this field would be more expensive and not very good for me as my scene could have quite a few if these?