Call function on all objects in trigger


I want to call the function that is in the OnTriggerStay but it’s only calling it for one object at a time. how can i make it so that it calls it for all the game objects at the same time? this will be used for an explosion-type damage.

using UnityEngine;
using System.Collections;

public class EnemyDamageZone : MonoBehaviour {

	public float AmountOfDamage;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {


	void OnTriggerStay (Collider ObjectToDamage){

		if(ObjectToDamage.gameObject == GameObject.FindGameObjectWithTag("Enemy")){

			ObjectToDamage.gameObject.GetComponent<ExperimentalEnemy> ().EnemyDamage (AmountOfDamage);




When you detonate the explosion, you can put a single:

That will give you an array of all objects in the sphere.

For purposes where you need a custom trigger shape, you would have to manually add objects to a list/array at OnTriggerEnter and remove objects from the list at OnTriggerExit and on detonation call the function on all the objects in the list but this can be a bit risky from my experience.

You’ll want to use Physics.SphereCastAll: Unity - Scripting API: Physics.SphereCastAll

It returns every hit within a radius and you can use that to get the ExperimentalEnemy component and apply damage for each.