如何破坏实例化对象统一c#

时间:2014-11-27 11:15:03

标签: c# unity3d

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);
    }
}

在上面的代码中,我的平台被实例化,当我的相机向前移动时,我必须摧毁我平台的尾部。怎么样?

1 个答案:

答案 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)