Project
Beginner Gameplay Scripting
Instantiate
Tutorial
Beginner
5 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Instantiate
Summary
How to use Instantiate to create clones of a Prefab during runtime.
Language
English
Recommended Unity Versions
4
1.
Instantiate

UsingInstantiate

using UnityEngine; using System.Collections; public class UsingInstantiate : MonoBehaviour { public Rigidbody rocketPrefab; public Transform barrelEnd; void Update () { if(Input.GetButtonDown("Fire1")) { Rigidbody rocketInstance; rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody; rocketInstance.AddForce(barrelEnd.forward * 5000); } } }

RocketDestruction

using UnityEngine; using System.Collections; public class RocketDestruction : MonoBehaviour { void Start() { Destroy (gameObject, 1.5f); } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
Arrays
Tutorial
Beginner
5 Mins
Unity Technologies