0

Hello there strangers,

I seem to be in a pickle over this matter, I have all the correct refrences for my scripts(I think!) but there is no object spawning and I keep getting the error message: Object refrence not set to an instance of an object

The following script is named PlayerController:

The error always trips on the following lines(Specifically the playerGun.isFiring) :

    if(Input.GetMouseButtonDown(0))
    {
        playerGun.isFiring = true;
    }
    else if (Input.GetMouseButtonUp(0))
    {
        playerGun.isFiring = false;
    }

playerGun is assigned in the following way:

public GunController playerGun;

The folllowing script is the GunController Script:

This is where I assign the isFiring method, but nothing seem to happen as it breaks on the above code.

public bool isFiring; // Boolean to check if the player is firing

Any help/Suggestions are much appreciated. As a note the GunController is attached to an object which is a child of another object which holds the playerController script.

Robertgold
  • 215
  • 6
  • 19
  • `public GunController playerGun;` does _not_ assign anything, it just _declares it. – oerkelens Dec 06 '17 at 09:45
  • @oerkelens So I need to set the playerGun to equal the script then? I don't get this error as it allows me to see all the public variables when i do playerGun.X/Y/Z yet afterwards has an error... – Robertgold Dec 06 '17 at 09:48
  • "set the playerGun to equal the script" does not mean anything, I am sorry. You need to assign some value to playerGun, like `= new GunController();` or something. I have no idea what script you keep talking about. – oerkelens Dec 06 '17 at 10:26
  • 1
    @Robertgold the public variable should appear in inspector when you select PlayerController gameObject in Unity, drag and drop the gun object int the inspector and it will work – Umair M Dec 06 '17 at 10:42
  • @UmairM Thanks that worked, I had completely forgotton that it could be that! – Robertgold Dec 06 '17 at 10:59

0 Answers0