Moving and Refering to Game Objects

This is getting to me because it seems to be something that just works but wont.

I have an empty scene with a floor. I created a new gameobject (cube) and called it MapIcon. I have an empty game object sitting in the scene called controller, and attached a script called CharacterMover.

In the script in the update function I have a simple ‘if button bushed then’ clause and inside it MapIcon.transform.Translate(vector3); but on running it doesn’t know what MapIcon is. I assumed that game objects in the same scene could be referenced like that?

So in my CharacterMover script I made var whatToMove : GameObject; and changed my code to read ‘if button pushed’ whatToMove.transform.Translate(vector3); but in the inspector it does not bring up the space for me to drag a game object into to set as this variable.

I have another script somewhere else that created a space in inspector to put game objects when I declared var something : GameObject; but wont do it here?

First question, how do you refer to game objects created in the same scene. Second, why is it not giving me the variable space in inspector?

No, object names are just strings that are associated with the object; they don’t automatically become variables that can be referenced directly in that way.

However, you can search for game objects by name and acquire references to them that way, e.g. using GameObject.Find() or Transform.Find().

Hm, not sure about that one. I use C# though, so maybe there’s something obvious there that I’m missing.

I’m sure someone else will be able to help with that though.

If var whatToMove is inside a variable, it is a temporary variable. Therefore, it won’t show in the Inspector.
If you have multiple errors messages, the script can not compile well, and the variable can not show at the moment.

As pointed out, it doesn’t work like that. Imagine having two GameObjects named MapIcon in your scene, there would be no way of telling which one you mean.

Did you place “var whatToMove : GameObject;” inside a function? It will only show up in the inspector if it’s placed outside your functions. If that isn’t the problem, it would help if you could post the code that isn’t working.