- Home /
how can i take reference to the clone and not to the Gameobject?
I have some GameObjects, and 2 of them are instatiate randomically, (it is a fight game) the AI, needs to know witch one is the main_character, well... the AI only look to the gameObject and not to this clone. (if i dont delete the gameobjec, the AI fight with the Game Object, but if there is only the clone, nothing rappens), please, help me XD, how can the AI see the clone (that will be instatiate)??
public GameObject Personagem_Principal;
void Start() { Personagem_Principal = Rounds.Selecionado_aux; }
in Round.cs:
public static GameObject Selecionado_aux; Selecionado_aux=Personagens[0];
Personagens[0] is the original GameObject
Answer by appferreira · May 24, 2012 at 09:58 PM
Hello.
Im kinda new at unity, but as far as i know you can use TAGs to identify the prefab and then use a FOR LOOP to go throught each one, or as far as i know all clones without a defined name are called TheNameOfTheGameObject (Clone), so you can use that name, but i think might be better to use the for loop with tags.
See what more experienced ppl say about this.
humm good idea, i think that i can try something whit tag... THX, i'll think in something... maybe will fix my bugs
@appferreira's suggestion is ok: register a tag in the Inspector - "Inimigo", for instance - and set the enemy prefab tag to it: all enemies instantiated from this prefab will have the tag "Inimigo". When you destroy an enemy, you can use GameObject.FindWithTag("Inimigo") to find one of the remaining enemies alive:
// when the enemy is destroyed, find a new one: if (!Selecionado_aux){ // if current enemy is dead... // find another one: Selecionado_aux = GameObject.FindWithTag("Inimigo"); }
Your answer

Follow this Question
Related Questions
Assigning gameobject to an instantiated prefab through script? 2 Answers
How to Instantiate and change velocity 2 Answers
How could I save all cloned objects in a scene, and load them back up on start? 1 Answer
Instantiating a GameObject from scene that changes 1 Answer
What can I do to make the objects I instantiated move with the background? 1 Answer