#why doesnt it let me drag the transform
1 messages · Page 1 of 1 (latest)
what
just started a thread to not flood the channel with our conversation
ok
so there are several ways you can go about doing what you want to do (if i understand you correctly)
first: try to avoid using public. If you want to have the same field in the inspector as you achieved with public, use:
[SerializeField] GameObject Ts;
yy, w8
k
next: You can drag stuff manually like you tried, but if your script is always attached to the same type of gameobject, it's better to get the Components you need via code, just like i showed you earlier:
ok
Transform gameObjectTransform
Void Start()
{
gameObjectTransform = GetComponent<Transform>();
}
this stuff
But it doesnt let me drag it#
ok, next: You defined Ts as a Gameobject, so you have to drag the entire Gameobject from the Hirarchy on the left side into your field. That should work
sweet. Now that you have the player in Ts you can do ts.transform and do all the transform stuff you want to do from there
Ok
If you only want to access transform it's better to change the Gameobject to a Transform, get the transform via GetComponent<>() and work from there.
ok
This saves you from writing "transform" everytime you want to do something and is a bit cleaner since your script cant accidentally access other components.