大体思路:
- 首先在脚本文件中写好要传入的GameObject,这个变量必须是Public的。
- 然后将要生成的模型与这个GameObject挂载。即可
上代码:
using UnityEngine;
using System.Collections;
public class CreatePrimitive : MonoBehaviour
{
public GameObject drone_reds;
private int ClickCount = 0;
void OnGUI()
{
if (GUILayout.Button("CreatePlane", GUILayout.Height(50)))
{
ClickCount += 1;
GameObject obj = (GameObject)Instantiate(drone_reds);
float mainX = drone_reds.transform.position.x;
float mainY = drone_reds.transform.position.y;
float mainZ = drone_reds.transform.position.z;
obj.transform.position = new Vector3(mainX + 6*ClickCount, mainY, mainZ);
}
}
}
|