enable/disable trigger component with finding objects in scene with tag

Hi Untiy Community,
I want to make a script that finds all gameobjects with the same name in scene and want to enable a trigger component on all these objects.

the gameobjects i am searching for will be generated in the scene if the game starts

Thx for any anwer :slight_smile:

I recommend you to use tags instead of name. This will be much easier to define. Hereโ€™s a code:

#pragma strict

private var ObjectsWithSameName : GameObject [];

function Start ()
{
	ObjectsWithSameName = GameObject.FindGameObjectsWithTag ("Tag");
    
	for (var object in ObjectsWithSameName)
	{
		print (object.gameObject.name);
		object.GetComponent.<BoxCollider> ().isTrigger = true;
	}
}