From my previous blog,we all know that what prefabs are. Now,I want to explain how we instantiate prefabs and what are its advantages.
public class preafabDemo : MonoBehaviour
{
var ball:GameObject;
// Use this for initialization
void Start ()
{
for (var i : int = 0;i < 10; i++)
{
Instantiate (ball, Vector3(20, 0, 0), Quaternion.identity);//Creates ten instances of ball game object.
}
}
}
Advantages-
1) We can change the Prefab being instanced without changing the code that instantiates it.
2) We can set up, test, and modify the Prefab quickly and easily in the Scene and Inspector.
0 Comment(s)