Set a GameObjects position on start?

I am new to Unity and I am trying to set a GameObjects position.z OnEnable, but can’t figure out how to do so?

I set the camera OnEnable like this:
camera.transform.position.z = -1.7;

My GameObject is called “inventory” and I have tried like this:
GameObject.GetComponent(‘inventory’).transform.position.z = -7;

But i get this error: An instance of type ‘UnityEngine.GameObject’ is required to access non static member ‘GetComponent’.

Not sure how to do this… Any help is appreciated :wink:

1 Answer

1

GameObject.GetComponent(‘inventory’).transform.position.z = -7;

In the above line, try a lowercase g on gameObject, or better still, the gameObject you are trying to access.

Also, it may be easier to stick the transform.position into Start() function on the object.