LoginSignup
4
4

More than 5 years have passed since last update.

Unity C# GameObjectのインスタンス化

Last updated at Posted at 2014-08-06
using UnityEngine;

public class Sample : MonoBehaviour {

    [SerializeField] 
    GameObject pCube; // InspectorでPrefabを登録しておく

    void Start () {

        GameObject gCube = Instantiate(pCube) as GameObject;
        // Object型をGameObjectにキャスト

        gCube.transform.parent = transform; // 自身の子に移動
    }
}

GameObject型にキャストする必要がある。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4