using UnityEngine;
using System.Collections;
public class myscript : MonoBehaviour {
public Transform platform;
public float z = 0.0f;
void Update ()
{
float c_z=0.0f;
Instantiate(platform,new Vector3(z++,0,0),Quaternion.identity);
Camera.main.transform.Translate (0,0,c_z=c_z+0.1f);
}
}
在上面的代码中,我的平台被实例化,当我的相机向前移动时,我必须摧毁我平台的尾部。怎么样?
答案 0 :(得分:0)
尝试:
using UnityEngine;
using System.Collections;
public class myscript : MonoBehaviour {
public Transform platform;
public float z = 0.0f;
private GameObject _obj;
void Update ()
{
float c_z=0.0f;
_obj = Instantiate(platform,new Vector3(z++,0,0),Quaternion.identity) as GameObject;
Camera.main.transform.Translate (0,0,c_z=c_z+0.1f);
}
}
然后只要你准备好销毁平台就打电话给Destroy(obj)
。