문서의 이전 판입니다!


타이머로 프리팹 제거하기

총알등의 프리팹을 일정 시간 후 제거하는 방법이다. (출처)

프리팹 만드는 법은 실시간으로 프리팹을 인스턴스화 하기 (Instantiating Prefabs at runtime) 참조.

	public float lifetime = 1.0f;
 
	void Awake()
	{
		Destroy(gameObject , lifetime);
	}
 

위의 방법으로 하면 본체가 제거된다. 클론을 제거하려면 아래와 같이 한다 (출처)

public class bolt_move : MonoBehaviour {
    GameObject item;
    public float speed;
    public float lifeTime = 1.0f; //life 
 
    void Start () {
        Destroy(GameObject.Find(item.name + "(Clone)"),lifeTime);
        //prefab timed removal 
        // http://answers.unity3d.com/questions/608561/i-need-to-destroy-prefab-clones.html
 
    }
 
    // Update is called once per frame
    void Update () {
		GetComponent<Rigidbody>().velocity = transform.forward * speed;
	}
}