강의

멘토링

커뮤니티

Inflearn Community Q&A

abcko0494's profile image
abcko0494

asked

C# and Unity, Getting Started with Real Games (Author's Lecture)

2.16 Implementing Enemy 1 - Creating Enemy Objects

코드 질문

Written on

·

186

0

public float GetHealth(){

         return health;

} 있으나 없으나 상관 없는거 같은데  이 코드는 무슨 역할을 하나요?

C#unity

Answer 1

0

kkirru님의 프로필 이미지
kkirru
Instructor

외부에서 health라는 변수에 직접 접근하지 못하게 private으로 선언하고,
GetHealth 함수를 public으로 선언하여 health 변수의 값만 확인할 수 있게 해놓은 것입니다!
그럼 외부에서 health 변수의 값을  바꿀 수 없겠죠ㅎㅎ (read-only)

abcko0494's profile image
abcko0494

asked

Ask a question