Issue after this lecture

Hi there,

I have just gone through this section, had a few issues back in Unity but managed to solve and now can’t move my player.
Here is the error message

Let’s start with a look at the PlayerController. While I don’t think we need to see the whole script, post the MoveToCursor() method in your PlayerController.cs here and we’ll have a look.
Don’t forget to format the code, you can select the code after you paste it and press the </> button to format it.

Hi there,

here is my code - issues occured after creating all the namespaces-

    private void MoveToCursor()

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        bool hasHit = Physics.Raycast(ray, out hit);
        if (hasHit)


There are two possible places in this method that could be providing a null reference error.
Camera.main and GetComponent();
If line 30 is the Camera.main.ScreenPointToRay() line, then check to make sure that your camera has the Main Camera tag on it. That’s how Camera.main finds the camera it’s supposed to be checking.
If it’s getComponent(), make sure that there is a Mover component on your character.

1 Like

Privacy & Terms