상수.


 상수는 변수와 사용법은 같으나 값이 변하지 않는다.

 선언방방

 const int A= 10; //const 키워드로 상수선언



using UnityEngine;
using System.Collections;

public class MouseClickTest : MonoBehaviour {

const int SCORE10 = 10;
const int SCORE20 = 20;
const int SCORE30 = 30;
const int SCORE40 = 40;

public int myScore = 50;

// Use this for initialization
void Start () {

}

void OnMouseDown(){
myScore = myScore - 10;



switch (myScore) {
case SCORE10: // 상수의 값을 적용
print("failed");
break; //구문의 끝
case SCORE20:
print("20");
GetComponent<Renderer>().material.color = Color.red;
break;
case SCORE30:
print("30");
break;
case SCORE40:
print("40");
break;
default : // case가 지정되지 않은 기본값
print("50");
break;
}

}



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


}
}

댓글

이 블로그의 인기 게시물

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

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

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