[Solved] How do I make a global mouseMove variable?

Update: This is fixed because we control the laser from the PlayerController script. I would still like to know how to do this though. I thought my code should’ve worked.

I set mouseMove to true on the PlayerController script to toggle between using the keyboard and the mouse. When mouseMove is true the ship moves with the mouse. I want to do the same thing with the laser, so when I click the left mouse button the projectile appears/fires.

PlayerController script:

public bool mouse Move;

Laser script:

private PlayerController playerController;
if (playerController.mouseMove){

The error is: Object reference not set to an instance of an object.

Hi Brady,

This is a little tricky without seeing more of what you are trying to achieve, however, the nullreferenceexception will most likely be pointing to the playerController within that if statement (assuming the error is thrown for that line).

You have the PlayerController set as public, have you instantiated this by getting a reference to it from the Start() method for example, using FindObjectOfType<>()?

I didn’t Instantiate. Thank you.

1 Like

You’re more than welcome :slight_smile: