Transform function

As explained in the video, we get permanent access to any game object’s transform. But how does unity know which game object’s transform we are manipulating, if we call the function without referring to any object (eg transform.Rotate(Vector3.forward);)? Am I missing something here?

Oh, I forgot that the C# script is a component of the game object, the rocket in this case. So we transform the game object of which the script is a component. Is that correct?

Basically yes, but at times there may be transforms of multiple objects mixed up and tangled in which case you would want to specify that is is this object’s transform by using this.transform, that is simplest explanation and would recommend reading up a bit on the subject:
C# OOP: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/object-oriented-programming
C# this: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/this

1 Like

OOP reflects the real world behavior of how things work. It is important because

  • It make visualization easier because it is closest to real world scenarios.
  • You can reuse the code, this saves time, and shrinks your project.
  • Once you know the concept, it makes you a cooler coder among your friends :wink: .

There are 3 basic features of object oriented programming language:

  • Inheritance
  • Polymorphism
  • Encapsulation

By using these features you can easily reuse your program or part of your program. Object oriented programming provides you a power to do programming in a very effective manner. Learn OOP concept and implement it in your daily programs.

Privacy & Terms