Hello there!
I have started to learn c# over the last few weeks and while programming a question came into my mind.
If I have a script attached to a gameobject, what’s the difference at calling “gameObject.transform” and just “transform”.
For example: If I want to get the current position of my Object I would do something like this:
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
Vector3 pos1 = gameObject.transform.position;
Debug.Log("Position1: " + pos1);
Vector3 pos2 = transform.position;
Debug.Log("Position2: " + pos2);
}
}
But when tested it gives out the exact same information. What is the difference? And for what do I need the “gameObject” when I can get the same information without it?
Thanks for your help in advanced!