Hello!
Transform thisTransform;
Public Vector3 direction = Vector3.zero;
void Awake(){
thisTransform = GetComponent<Transform>();
direction = thisTransform.TransformDirection(Vector3.forward); //This line!
}
This is where I get the “Object reference not set to an instance of an object” error.
The thing is, I have defined thisTransform as an object, so what more is there to “define”?
Any ideas?
You haven’t put the character controller in the controller variable I’m guessing. The normal way to do this would be to use GetComponent:
void Start() {
controller = GetComponent(CharacterController);
}
It’s fine in Awake. I tried it exactly as written (well, the P in public should be lower-case.) The docs even say Awake is called after all objects are created (which I didn’t realize – thought it was called after each individually was created.)
But, yeah, the error is probably saying that thisTransform
is null. Try printing it to be sure. Is the script on some odd object that doesn’t have a transform? (not sure how – even empties have transforms.)