- Home /
Instantiating Sprites
I'm trying to use prefabs to instantiate a sprite for a basic shooting setup however MonoDevelop gives me the error:
"The name 'playerShot' does not exist in the current context"
Here is my code:
using UnityEngine;
using System.Collections;
public class PlayerControl : ShipClass
{
void Start ()
{
//useless for now
}
void Update ()
{
if (Input.GetButtonDown ("Fire2"))
{
Debug.Log ("Fire2 pressed!");
Instantiate(playerShot);
}
}
}
Where playerShot in this case is the prefab that I have created. I think I'm having trouble getting my head around how a script handles a prefab so any help on this matter would be appreciated. Thanks in advance.
Answer by Jinxology · Jan 24, 2014 at 08:00 PM
Put "playerShot" in quotes.
Instantiate("playerShot");
What is the significance of the " " if you don't $$anonymous$$d me asking? I found a different way to instantiate but if this works it would be simpler to follow my own code.
Using quotes signifies the name of an object, while leaving them off would signify an object type. Hope that helps. If my solution works, would you $$anonymous$$d clicking accept answer? Thanks!
I don't have time to implement it tonight or tomorrow. I believe you though. I'll let you know what happens! Thanks for the input!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Instantiate already connected players. 0 Answers
Making change to an instance of a prefab doesn't work... 1 Answer
Lower Draw Calls For Sprites 2 Answers