- Home /
need help on prefab spawning
hi, i have a situation where at initial i have a prefab, which on clicking by mouse spawns two prefabs. trying to figure it out. need help how to spawn.
Provide some code and more explanation about whats going wrong
actually am i dont know how and where to start. i need help on how to start with.
Answer by Utamaru · Mar 20, 2015 at 09:42 AM
To spawn prefab use Instantiate method. If you want to spawn this object every time when user performs mouse click event, use this code:
public GameObject SomePrefab;
void Update()
{
if(Input.GetMouseButtonDown(0)
{
Instantiate(SomePrefab, Vecto3.zero, Quaternion.identity);
}
}
ya ur code is correct and this is how it has to be, but the situation is not clicking mouse button and then instantiating,
when i press the play button i should see a prefab on the game screen, which clicking upon it has to spawn two prefabs.
this is the situation.
Your answer
Follow this Question
Related Questions
Problem using boids algorithm for chasing enemies. 1 Answer
Can I use transorm.position here? 1 Answer
build Simple AI pacman Style 0 Answers
random positioning of prefabs in memory game 0 Answers
Bestpractices for statemachines 0 Answers