Hey guys, I have a huge problem which is stopping me from continuing with my game. I’m trying to make it, so when you press the space bar, it fires a fireball from a spawnpoint. Here’s the script:
var bullitPrefab:Transform;
function Update () {
if(Input.GetKeyDown(KeyCode.Space)){
var bullit = Instantiate (bullitPrefab, GameObject.Find("spawnPoint").Transform.position, Quaternion.identity);
}
}
I have set the 'bullitPrefab’to my fireball, but it just says it’s a ‘NullReferenceException.’ What have I done wrong?
Is your spawnPoint an object in the scene? If it is check that it is called spawnPoint because you are trying to find it by name. To see if that is the problem comment out the instantiation line and put
Debug.Log(GameObject.Find("spawnPoint"));
If you get a null reference you know its a problem trying to access the spawnPoint.