
Instantiate(インスタンス化)
Tutorial
Beginner
+0XP
5 mins
(12)
Unity Technologies

Instantiate 関数を使ってランタイム中にプレハブのクローンを作成する方法を学びます。
本チュートリアルは Beginner Scripting プロジェクトに含まれています。
前回のチュートリアルは:Classes
次のチュートリアルは:Arrays
Languages available:
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);
}
}