How can i spawn a prefab into the game when a specific even happens?
2 Answers
2Try this :
var prefabToSpawn : GameObject;
var spawnLocation : Vector3;
function RunEvent () {
Instantiate(prefabToSpawn, spawnLocation, Quaternion.identity);
}
Then simply run the function at the desired time.
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);
}
}
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.
– Eric5h5