- Home /
Question by
ninjaboynaru · Jul 04, 2013 at 08:40 PM ·
nullreferenceexceptionfunctionclassclasses
Instantiate inside class function returns NullReference
Unity is giving me an error Null Reference Exception on this line inside the Fire Function
tempBulPref = GameObject.Instantiate(tempoAmmoPref, fireLocation.transform.position, fireLoc
Everything Works fine until I call the Fire Function
class Weapon extends Item{
var range : float;
var rateOfFire : int;
var weaponType : weaponType;
var clipSize : int;
var fireLocation : Transform;
var bulletPrefab : ammoType;
var gWeaponManager : GameObject;
var tempoAmmoPref : GameObject;
function SetValues(){
gWeaponManager = GameObject.Find("Global Weapons Class Manager");
Debug.Log(gWeaponManager.name);
}
function Fire(){
var tempBulPref : GameObject;
tempBulPref = GameObject.Instantiate(tempoAmmoPref, fireLocation.transform.position, fireLocation.transform.rotation);
Debug.Log("Shots Fired");
}
}
Comment
Best Answer
Answer by ninjaboynaru · Jul 04, 2013 at 08:49 PM
Found the answer to the question right after I posted.
Change tempBulPref to a Object
and I forgot to assign a tempoAmmoPref