Fill inspector variable via Unity code

Asked

Viewed 51 times

0

I’m trying the following:

When the enemy is instantiated I want him to target my player, all right, but when the enemy comes to the game he does not fill the variable Alvo as I pointed out below, the inspector looks like (None).

var Alvo  : Transform;

function Update () {
    if (!Alvo)
 {
   Alvo = GameObject.Find("/Tanque").transform;  
 }
  • Why are you going through /? This is to go through the hierarchy, your object "Tank" is inside another object?

  • yes he is inside another object

  • Try to do "Other Tank".

  • blz, I’m going to go now

  • oops, I came back, it worked, it was like this code:

  • if (!Target) { Target = Gameobject.Find("tank/tank"). Transform; }

  • but I tried to put that code in the start, and it worked.

  • I want to thank you for your attention, thank you very much!

  • Answer your own question, just to be a reference for the next people who see it can get it out of the solution :)

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.