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?
↧