the Title say it all.
How do I find out how many objects have a certain tag, or get references to all gameobjects that are tagged with that particular tag?
the Title say it all.
How do I find out how many objects have a certain tag, or get references to all gameobjects that are tagged with that particular tag?
Use the "FindGameObjectsWithTag" function. Here's a c# example:
// to count the number of objects:
int enemyCount = GameObject.FindGameObjectsWithTag("Enemy").Length;
// to get an array of references to all those objects:
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
and in Javascript:
// to count the number of objects:
var enemyCount : int = GameObject.FindGameObjectsWithTag("Enemy").Length;
// to get an array of references to all those objects:
var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");
in c # try this code to find out the references of all objects specific name
obsticals = GameObject.FindGameObjectsWithTag(“hurdles”);
if (obsticals != null)
{
foreach (GameObject roadHurdles in obsticals)
{
hurdleScripts hurdle = roadHurdles.GetComponent<hurdleScripts>();
hurdle.variable in the next scripts…= somthing;
// }
//}