클래스, 읽기전용 변수와 읽기쓰기 변수.

public class Enemy  {

int _hp;

public int hp{ // 외부에서 해당값에 변수대입 불가능
get{
return _hp; //
}
}
}


public class Enemy  {

int _hp;

public int hp{
get{
return _hp;
}
set{
_hp = value; // value는 외부의 에서 전달받은 값을 대입
}
}

}





using UnityEngine;
using System.Collections;

public class Enemy  {

int _hp;

public int hp{
get{
return _hp;
}
set{
if( value > 50){  // 방어코드
_hp = 50;
}else{
_hp = value;
}
}
}

}


댓글

이 블로그의 인기 게시물

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

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

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