1
\$\begingroup\$

I m new to unity and C#.

I suspect that transform.find() function below does not need actual object reference like

player.transform.find()

because it transform find is already applied to the gameObject the script is attached to? Am I right? Why transform.find() does not have any game object in front of it?

public class PlayerControl : MonoBehaviour{

private Transform groundCheck ;


void Awake()
{
    groundCheck = transform.Find("groundCheck");
}
\$\endgroup\$
1
\$\begingroup\$

transform is the instance of Transform which is a public attribute of GameObject. That is why we don't need it. But you can use gameObject.transform.Find("groundCheck"); though. Similarly gameObject is the instance of GameObject representing the GameObject in which this script is attached.

\$\endgroup\$

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.