차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
unity:타이머로_프리팹_제거하기 [2015/08/22 20:00] V_Lunity:타이머로_프리팹_제거하기 [2018/02/22 11:34] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 +{{tag>타이머 클론 prefab 프리팹 제거하기}}
 ====== 타이머로 프리팹 제거하기 ====== ====== 타이머로 프리팹 제거하기 ======
  
  
 총알등의 [[unity:prefabs|프리팹]]을 일정 시간 후 제거하는 방법이다. 총알등의 [[unity:prefabs|프리팹]]을 일정 시간 후 제거하는 방법이다.
-프리팹 만드는 법은 [[unity:instantiatingprefabs]] 참조.+([[http://answers.unity3d.com/questions/250873/destroying-a-prefab-bullet-after-time.html|출처]])
  
 +프리팹 만드는 법은 [[unity:instantiatingprefabs]] 참조.
 <file csharp> <file csharp>
- var lifetime = 1.0;+ public float lifetime = 1.0f;
    
-     function Awake() + void Awake() 
-     +
-         Destroy(gameObject , lifetime); + Destroy(gameObject , lifetime); 
-     }+ }
  </file>  </file>
 + 
 +[[prefab]]에 스크립트를 넣으면 된다. 
 +
 +
 +
 +클론을 제거하려면 아래와 같이 한다 ([[http://answers.unity3d.com/questions/608561/i-need-to-destroy-prefab-clones.html|출처]])
 +
 +<file csharp>
 +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;
 + }
 +}
 +
 +</file>
 +
  
-출처: [[http://answers.unity3d.com/questions/250873/destroying-a-prefab-bullet-after-time.html|유니티 질답]] 
  
-{{tag>타이머로 프리팹 제거하기}}