Skip to main content
added 204 characters in body
Source Link
Jonathan Connell
  • 2.8k
  • 1
  • 22
  • 28

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

int count = 0; GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") ++count; } 

While this should work (from memory)Edit:

If you're using the UI to add instances to the spawner, that means that the spawner, and the objects it is supposed to spawn, are already instanced at startup. I would not recommenddon't think this is the best way to go about it. I would instead implementpersonally add a script that makes use ofto the messaging systemsspawner with an Enum for each monster type. This scripts behaviour would be to check if it holds an instance to an object, via SendMessageif not create one of the Enum type and keep the reference.

I'll need to get out Unity later and check, but this should workIf you haven't tried overloading UI yet, although I'm not sure exactly what it is you're trying to do ;)can be quite easy and help enormously in creating a more suitable editor for your game.

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

int count = 0; GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") ++count; } 

While this should work (from memory) I would not recommend it. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

int count = 0; GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") ++count; } 

Edit:

If you're using the UI to add instances to the spawner, that means that the spawner, and the objects it is supposed to spawn, are already instanced at startup. I don't think this is the best way to go about it. I would personally add a script to the spawner with an Enum for each monster type. This scripts behaviour would be to check if it holds an instance to an object, if not create one of the Enum type and keep the reference.

If you haven't tried overloading UI yet, it can be quite easy and help enormously in creating a more suitable editor for your game.

added 15 characters in body
Source Link
Jonathan Connell
  • 2.8k
  • 1
  • 22
  • 28

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

int count = 0; GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") //DoSomething++count; } 

While this should work (from memory) I would not recommend it. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") //DoSomething } 

While this should work (from memory) I would not recommend it. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

int count = 0; GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") ++count; } 

While this should work (from memory) I would not recommend it. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

added 834 characters in body
Source Link
Jonathan Connell
  • 2.8k
  • 1
  • 22
  • 28

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") //DoSomething } 

While this should work (from memory) I would not recommend it, as it goes against the Component style that Unity imposes. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") //DoSomething } 

While this should work (from memory) I would not recommend it, as it goes against the Component style that Unity imposes. I would instead implement a script that makes use of the messaging systems, via SendMessage.

From Unity Reference :

// This will return the game object named Hand in the scene. hand = GameObject.Find("Hand"); 

You must remember that when trying to access objects via script, any inactive GameObjects are not included in the search. And that this will only return one object.

If you want to create the same behaviour as 'FindGameObjectsWithTag', you'll have to implement the function yourself.

In one of my games, for each level I used a GameObject to parent all the other objects, this way it was easier to access the objects. You could do something like :

GameObject[] children = GetComponentsInChildren<GameObject>(); foreach (GameObjectchild in children ) { if(children.name == "WantedName") //DoSomething } 

While this should work (from memory) I would not recommend it. I would instead implement a script that makes use of the messaging systems, via SendMessage.

I'll need to get out Unity later and check, but this should work, although I'm not sure exactly what it is you're trying to do ;)

added 834 characters in body
Source Link
Jonathan Connell
  • 2.8k
  • 1
  • 22
  • 28
Loading
Source Link
Jonathan Connell
  • 2.8k
  • 1
  • 22
  • 28
Loading