1
\$\begingroup\$

Looking at example code for mesh deformation in unity

https://answers.unity.com/questions/746673/sine-wave-mesh-deform-with-different-directions.html

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.

\$\endgroup\$
  • \$\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
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\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.