- Home /
Question by
DNP · Sep 01, 2012 at 02:44 AM ·
javascriptinstantiateprefab
Prefab Spawning
How can i spawn a prefab into the game when a specific even happens?
Comment
Use Instantiate, though I guess you know that since you used it as a tag. Providing more detail would help to understand what the question actually is.
Answer by gamenut30111 · Sep 01, 2012 at 03:45 AM
Try this :
var prefabToSpawn : GameObject;
var spawnLocation : Vector3;
function RunEvent () {
Instantiate(prefabToSpawn, spawnLocation, Quaternion.identity);
}
Then simply run the function at the desired time.
Answer by OperationDogBird · Sep 01, 2012 at 03:46 AM
Like @Eric5h5 stated, Instantiate is what you will need. Heres an example using a trigger. When the Player enters the trigger we spawn 'somePrefab' at the players position and rotation.
public var somePrefab:Transform;
function OnTriggerEnter(other:Collider)
{
if(other.CompareTag("Player"))
{
Instantiate(somePrefab,other.transform.position,other.transform.rotation);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613080500im_/https://answers.unity.com/themes/thub/images/avi.jpg)