- Home /
Question by
BuildIntoGames · Aug 23, 2013 at 10:12 PM ·
errorinstance
Object reference not set to an instance of an object error
I get this error whenever I run my game... help?
Heres the code of where it breaks.
function Update () {
var SCAR = GameObject.FindWithTag("SCAR");
if (SCAR.GetComponent(PickupWeaponSystemSCAR).pickedup == false) {
bulletsGUI.text = "" + currentbullets + " / " + maxbullets + " Bullets";
}
if (SCAR.GetComponent(PickupWeaponSystemSCAR).pickedup == true) {
currentbullets = 30;
maxbullets = 30;
}
}
Comment
Which line is the Nullref? Weapon is correctly tagged? Object is snapped in in the inspector? Script PickupWeaponSystemSCAR is correctly placed on the weapon and the variable pickedup exists in that script?
@BuildIntoGames - this is your third question related to NullReferenceException. This kind of errors is very easy to locate and fix, you just have to learn a bit about debugger and debugging.
Open your console window and read what line its throwing up on.