- Home /
Question by
$$anonymous$$ · Dec 30, 2014 at 02:23 AM ·
c#2dinstatiateshot
Object name not found?
I have an object I'm trying to instantiate, yet I keep getting this error message: the name 'zapperbullet' does not exist in the current context. here is my code:
if (Input.GetKey("a"))
Instantiate (zapperbullet, transform.position,transform.rotation);
Comment
Answer by Srki94 · Dec 30, 2014 at 02:29 AM
You can't just use it like that, you have to define it somewhere or tell code where to find that thing.
Do this :
public GameObject ourzapper;
if (Input.GetKey("a"))
{
Instantiate (ourzapper, transform.position, transform.rotation);
}
Save script, go back to editor and drag and drop zapperbullet to new field that was created there, then run the game and press A. You will see new object instantiated.