Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Instantiating Prefabs at runtime

    • 0
    • 6
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 716
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: