Hey guys, I have a little problem with my script where I cannot move the GameObject/Player because of the following error:
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Update () (at Assets/Scripts/Character/PlayerMovement.js:14)
The problem only shows when the I am running the game, the problem is happening because I am using Unity 4 and the tutorial is an older version. This is the script I have written:
#pragma strict
var WalkAcceleration : float = 5;
var CameraObject : GameObject;
function Start ()
{
}
function Update ()
{
//Rotation Y was made public in MouseLook script
transform.rotation = Quaternion.Euler(0, CameraObject.GetComponent(MouseLook).rotationY, 0);
rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * WalkAcceleration, 0, Input.GetAxis("Vertical") * WalkAcceleration);
}
Thanks for the help guys, really means a lot.
Did you remember to drag the camera object to CameraObject in the inspector?
– ArithanYeah, I have done that already, still can't figure it out :(
– F3RILLAThanks for all the help guys, I have sorted the problem out. I made an error in my MouseLook Script and BenProductions you was right :), thanks buddy
– F3RILLAPlease close the question then :)
– Benproductions1That's the problem, I don't know how to :D
– F3RILLA