Skip to content

Instantly share code, notes, and snippets.

@ged1959
Last active August 29, 2015 14:16
Show Gist options
  • Save ged1959/3949f76d5352351eb12c to your computer and use it in GitHub Desktop.
Save ged1959/3949f76d5352351eb12c to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class CreateButton: MonoBehaviour {
public GameObject cube;
//親子関係の設定に使うために、あらかじめ設定。ここから。
private GameObject cubeparent;
private GameObject Cube;
//ここまで。
void Start () {
cubeparent = GameObject.Find ("CubeParent");
}
void OnGUI()
{
if(GUI.Button(new Rect(70, 10, 100, 50), "GENERATE"))
{
float x = Random.Range(-6.0f, 6.0f);
float y = Random.Range(-3.0f, 3.0f);
float z = Random.Range(-3.0f, 3.0f);
//オブジェクトに代入するには、以下の(GameObject) が大切、ぽい。
Cube = (GameObject) Instantiate(this.cube, new Vector3(x, y, z), Quaternion.identity);
//Instantiate(this.cube, new Vector3(x, y, z), Quaternion.identity);
Cube.transform.parent = cubeparent.transform;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment