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

NullReferenceException, still the code is working?

$
0
0
Hi there I'm getting this error: NullReferenceException: Object reference not set to an instance of an object PlayerStatus.CarAccel () PlayerStatus.Update () Apparently my script is not finding another script component but everything works fine, can't really say what's happening here any help will be appreciated!! public class PlayerStatus : MonoBehaviour { public static PlayerStatus playerStats; [SerializeField] public CarSelector carScript; [SerializeField] private int chargerLevel; [SerializeField] private int corvetteLevel; [SerializeField] private int shelbyLevel; [SerializeField] private int upgradeLevel = 1; [SerializeField] private int upgradeModifier = 1; [SerializeField] private int defaultAccel; [SerializeField] private int modAccel; [SerializeField] private int currentCar; private void Awake() { if (playerStats == null) { DontDestroyOnLoad(gameObject); playerStats = this; } else if (playerStats == this){ Destroy(gameObject); } if (GetComponent() != null) { carScript = carScript.GetComponent(); } else { Debug.LogWarning("Missing script"); } } // Update is called once per frame void Update () { CurrentVehicle(); CarAccel(); } int CurrentVehicle() { currentCar = carScript.seleccionPositiva; return currentCar; } int CarAccel() { switch (CurrentVehicle()) { case 0: chargerLevel = carScript.charger.currentLevel; switch (chargerLevel) { case 1: modAccel = carScript.corvette.accel * 1; lvl1(); break; case 2: modAccel = carScript.corvette.accel * 3; lvl2(); break; case 3: modAccel = carScript.corvette.accel * 5; lvl3(); break; } break; I do get the car model and the acceleration even the modified acceleration but I get this error whenever I compile the script, sometimes points to CarAccel(); and I do get the Missing script warning, what I'm I doing wrong here?

Viewing all articles
Browse latest Browse all 2891

Trending Articles