문서의 이전 판입니다!


타이머로 프리팹 제거하기

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

프리팹 만드는 법은 실시간으로 프리팹을 인스턴스화 하기 (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 
	// Use this for initialization
	void Start () {
        Destroy(GameObject.Find(item.name + "(Clone)"),lifeTime);
        //prefab timed removal 
        // 
    }
 
    // Update is called once per frame
    void Update () {
		GetComponent<Rigidbody>().velocity = transform.forward * speed;
	}
}

unity/타이머로_프리팹_제거하기.1466578631.txt.gz · 마지막으로 수정됨: 2016/06/22 15:27 저자 115.93.88.196
CC Attribution-Noncommercial-Share Alike 4.0 International 별도로 명시하지 않을 경우, 이 위키의 내용은 다음 라이선스에 따라 사용할 수 있습니다: CC Attribution-Noncommercial-Share Alike 4.0 International