Monday, June 27, 2011

// Instantiates 10 copies of prefab each 2 units apart from each other


Object.Instantiate  

static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object

Description

Clones the object original and returns the clone.
Clones the object original, places it at position and sets the rotation to rotation, then returns the cloned object. This is essentially the same as using duplicate command (cmd-d) in Unity and then moving the object to the given location. If a game object, component or script instance is passed, Instantiate will clone the entire game object hierarchy, with all children cloned as well. All game objects are activated.
See Also: In depth Prefab Instantiate discussion

// Instantiates 10 copies of prefab each 2 units apart from each other

var prefab : Transform;

for (var i : int = 0;i < 10; i++) {
Instantiate (prefab, Vector3(i * 2.0, 0, 0), Quaternion.identity);
}
Instantiate is most commonly used to instantiate projectiles, AI Enemies, particle explosions or wrecked object replacements.

No comments:

Post a Comment