- Home /
Question by
frankyboy450 · Oct 05, 2013 at 11:21 PM ·
c#gameobjectname
How to SetTrigger all colliders with a specific name
Hi. Is it possible to find all GameObjects in my scene called like "Floor" for example and set the "IsTrigger" to true on them?
Comment
Best Answer
Answer by Cherno · Oct 05, 2013 at 11:38 PM
var FloorArray : GameObject[];//Declare an array, to be filled later
FloorArray = GameObject.FindGameObjectsWithTag("Floor");//fill the array
function SetFloorTrigger()
{
for(var CurrentFloor : GameObject in FloorArray)//iterate through the contents of your array, "CurrentFloor" is a temporary name that references each GameObject inside the Array
{
CurrentFloor.collider.isTrigger = true;
}
}
Your answer
Follow this Question
Related Questions
Separate GameObject name? 2 Answers
GameObject.Find can't find the object after i changed her name 1 Answer
c# - Rename Instatiated GameObject - Solved 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer