'게임오버'에 해당되는 글 1건

  1. 2014.08.05 오브젝트를 3개 이상 먹으면 Game Over 처리
Unity2014. 8. 5. 15:47


public class PlayerController : MonoBehaviour {


public GUIText countText;

public float moveSpeed = 100f;

public GUIText resultText;

private int count;


// Use this for initialization

void Start () {

count = 0;

countText.text = "count: " + count.ToString ();

resultText.text = "";

}

// Update is called once per frame

void FixedUpdate () {

float h = Input.GetAxis ("Horizontal");

float v = Input.GetAxis ("Vertical");


rigidbody.AddForce (new Vector3 (h, 0f, v) * moveSpeed * Time.deltaTime);

SetCountText ();

}


void OnTriggerEnter(Collider other) {


if(other.gameObject.tag == "Item")

{

//Box Collider 인스펙터에서 Is Trigger 체크해서 활성화!

other.gameObject.SetActive(false);


count += 1;

countText.text = "count: " + count.ToString ();

//Destroy(other.gameObject);

}

//Destroy(other.gameObject);

}

void SetCountText() {

if (count >= 3) {

resultText.text = "Game Over";

countText.text ="";

}

}

}

'Unity' 카테고리의 다른 글

Build 설정 및 실행  (0) 2014.08.06
Rail에서 카메라 이동  (0) 2014.08.05
GUI Text 는  (0) 2014.08.05
플레이어에서 충돌 물체 삭제 처리  (0) 2014.08.05
카메라가 캐릭터 따라감, 위치 고정. rigidbody  (0) 2014.08.05
Posted by 코드버무려