GameObject.Find("In-Game-Object") Position


I need to know if I need to make seperate script (to use transform.position) and then attach it to each game object to know about the individual positions.

`public static Vector3 Object_1,

// Use this for initialization
void Start ()
if (GameObject.Find(“Object_1”))
Object_1 = transform.position;
if (GameObject.Find(“Object_2”))
Object_2 = transform.position;
if (GameObject.Find(“Object_3”))
Object_3 = transform.position;
if (GameObject.Find(“Object_4”))
Object_4 = transform.position;
if (GameObject.Find(“Object_5”))
Object_5 = transform.position;

The above is in one script file, attached to each Object, [1,5]. The intention is to know about each objects individual position.

When I go to Debug.Log(Object_2) I see that it is either 0,0,0 (not true) or overwritten..However, Logging, Object_1 is fine...Is it true that I need to make seperate script for each game object?

Okay, So what objects are in your hierarchy?

I read your code like this:

When this object is loaded look for (Game)Objects 1 through 5 and save their positions into Vector3 objects labeled "Object_1" through "Object_5".

If you'd like to access the transform try something like this:


Read more about selectors here:

Each GameObject has a Transform component automatically:

Also, you might want to try and use tags if you find yourself accessing a lot of the same type of object. read more about them here:

Good luck with whatever you're doing. If you want more specific information try expressing what the overall goal is next time. :)


if(star1position){transform.position = GameObject.Find(“Star1Position”).transform.position;}

in this case i got a bool but u can simply

transform.position = GameObject.Find(“Star1Position”).transform.position;