- Home /
Question by
falconfetus8 · Feb 04, 2013 at 03:25 AM ·
instantiateprefabnull
The prefab you want to instantiate is null. Tried googling, didn't help.
Hello. I know this question has already been asked a million times, but none of the posts that I have found seem to be working for my situation. I'm trying to make the game fire a bullet when the player left-clicks. The bullet is a prefab, and I'm trying to instantiate it. Here's my code: #pragma strict
function Start () {
}
function Update () {
//Fire a bullet when the player clicks
if (Input.GetMouseButtonDown(0)){
var bullet_prefab: GameObject;
Instantiate(bullet_prefab,transform.position,transform.rotation);
}
}
And here's a screenshot of my project so you can see how the prefab is set up:
And here's the player's GameObject so you can see how I have the script put on there, in case that helps.
Comment
Answer by Wolfram · Feb 04, 2013 at 03:56 AM
You declared bullet_prefab locally in Update. Move it at the top of your script. Didn't it make you wonder that it wasn't possible for you to actually assign a bullet prefab to your script in the inspector?