GUI 설정
부스터 아이템 작업을 완료 했습니다. 하지만 부스터 아이템을 몇개 가지고 있는지 알수있는 방법은 플레이어가 그것을 기억하는수 밖에 없습니다. 이 방법을 개선하려면 GUI를 통해서 화면에 표시하는 방법이 있습니다. 아이템 개수 뿐만아니라 얼마나 이동했는지 또한 표시할수있씁니다.
GUIText를 생성하고 GUI의 자식으로 둡니다. 위치는 (0.01, 0.99, 0), Anchor 는 upper left, font size 20 그리고 normal style로 설정하니다. 이름은 Boosts Text입니다..
Distance Text도 생성합니다. 위치는 (0.5, 0.99, 0), font size 30 그리고 bold style.Anchor 는upper center.
GUIManager 에 두개의 변수를 선언하고 할당합니다.
public GUIText boostsText, distanceText, gameOverText, instructionsText, runnerText;

Runner 에서
GUIManager 를 수정할수 있게 스테틱 변수와 함수들을 만듭니다. 아래와 같이 스테틱 함수를 만들면 어디서든 접근이 가능합니다. private static GUIManager instance;
void Start () {
instance = this;
GameEventManager.GameStart += GameStart;
GameEventManager.GameOver += GameOver;
gameOverText.enabled = false;
}
public static void SetBoosts(int boosts){
instance.boostsText.text = boosts.ToString();
}
public static void SetDistance(float distance){
instance.distanceText.text = distance.ToString("f0");
}Runner 에서 위에 함수를 호출해서 값들을 변경해줍니다. void Update () {
if(Input.GetButtonDown("Jump")){
if(touchingPlatform){
rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
touchingPlatform = false;
}
else if(boosts > 0){
rigidbody.AddForce(boostVelocity, ForceMode.VelocityChange);
boosts -= 1;
GUIManager.SetBoosts(boosts);
}
}
distanceTraveled = transform.localPosition.x;
GUIManager.SetDistance(distanceTraveled);
if(transform.localPosition.y < gameOverY){
GameEventManager.TriggerGameOver();
}
}
private void GameStart () {
boosts = 0;
GUIManager.SetBoosts(boosts);
distanceTraveled = 0f;
GUIManager.SetDistance(distanceTraveled);
transform.localPosition = startPosition;
renderer.enabled = true;
rigidbody.isKinematic = false;
enabled = true;
}
public static void AddBoost(){
boosts += 1;
GUIManager.SetBoosts(boosts);
}
'유니티 > 스크립트' 카테고리의 다른 글
| [런게임] 유니티 3D로 러너 게임 만들기 - 완성본 (0) | 2014.01.14 |
|---|---|
| [런게임] 유니티 3D로 러너 게임 만들기 - 파티클 이펙트 (0) | 2014.01.14 |
| [런게임] 유니티 3D로 러너 게임 만들기 - GUI 설정 (0) | 2014.01.14 |
| [런게임] 유니티 3D로 러너 게임 만들기 - 파워업! (0) | 2014.01.14 |
| [런게임] 유니티 3D로 러너 게임 만들기 - 이벤트 사용하기 (0) | 2014.01.14 |
| [런게임] 유니티 3D로 러너 게임 만들기 - 게임오버 (0) | 2014.01.13 |
Trackback 0 And
Comment 0


