Since LearningCurve is already attached to the Main Camera, let's grab the Transform component from the Main Camera and store it in a public variable:
- Add a new public Transform type variable, called camTransform, to LearningCurve:
private Transform camTransform;
- Initialize camTransform in Start using the GetComponent method from the GameObject class:
- Use the this keyword, since LearningCurve is attached to the same GameObject component as the Transform component.
- Access and debug the localPosition property of camTransform using dot notation:
void Start()
{
camTransform = this.GetComponent<Transform>();
Debug.Log(camTransform.localPosition);
}
We've added an uninitialized private Transform variable at the top of LearningCurve and initialized it using the GetComponent method inside Start. GetComponent finds the Transform component attached to this...