GameObjectで空のGameObjectを生成し、そのオブジェクトにAddComponentでコンポーネントを追加する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CreateObject : MonoBehaviour { | |
private GameObject obj; | |
void Start () { | |
//空のGameObjectを生成する | |
obj = new GameObject("object_name"); | |
//コンポーネントを追加する | |
obj.AddComponent<Rigidbody>(); | |
obj.AddComponent<BoxCollider>(); | |
//オブジェクトのコンポーネントを取得し、パラメータを変更する | |
obj.GetComponent<Rigidbody>().isKinematic = true; | |
} | |
void Update () { | |
} | |
} |