Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

False Error: Object reference not set to instance of object

$
0
0
Hi, I have a C# script: public class FPS_GunController : MonoBehaviour { public GameObject gun; public Gun gunScript; // Use this for initialization void Start () { gunScript = gunScript.GetComponent(); } // Update is called once per frame void Update () { //Check for keypress if (Input.GetButtonDown("Fire1")) { gunScript.Fire(); } if (Input.GetButtonDown("Switch Mode")) { gunScript.SwitchMode(gunScript.currentMode + 1); } if (Input.GetButtonDown("Fire2")) { gunScript.Aim(); } } } but Unity throws me this Error: NullReferenceException: Object reference not set to an instance of an object FPS_GunController.Update () (at Assets/Scripts/FPS_GunController.cs:22) This error appears to be wrong, as the Method gets called, and I checked that it is assigned. What is the problem here?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>