Destroy( gameObject);

Destroy( gameObject);

Destroy();  게임 오브젝트를 사라지게(죽일때) 쓰는 함수
gameObject에서 앞의 g가 소문자일 경우 스크립트가 연결되어 있는 해당 게임오브젝트이다.(자신)




using UnityEngine;
using System.Collections;

public class MouseClickTest : MonoBehaviour {

public int hp = 100;

// Use this for initialization
void Start () {
print (hp);
}

void OnMouseDown(){
hp = hp - 10;

if (hp < 1) {
print ("killed...");
Destroy (gameObject);
} else {
print("live");
print(hp);
}

}



// Update is called once per frame
void Update () {


}
}

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법