Looking at example code for mesh deformation in unity


And i see theyve used

 public Transform Target1;
 public Transform Target2;

 void CalculateWaves ()
     waves[0].Direction = Target1.position - transform.position;
     waves[1].Direction = Target2.position - transform.position;

And i dont understand the difference between Target1.position and transform.position without any reference to an instance.

Arent they the same thing. And how does transform.position function without a reference.

  • \$\begingroup\$ Note that Transform, the class, is spelled with an uppercase T. When you see a lowercase t transform it's not referring to the class itself, but to a variable or property (generally one that's populated with an instance of the Transform class - see jhocking's answer) \$\endgroup\$ – DMGregory Oct 2 '18 at 18:36

The keyword 'transform' by itself is equivalent to writing 'this.transform'. In other words, it's the transform of the object that the script is on.

  • \$\begingroup\$ Now that makes sense. \$\endgroup\$ – Tim Oct 2 '18 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.