Public variable or Property? - Unity Forum


[SerialiseField] 

Used whenever a variable needs to be exposed to the inspector.

변수를 인스펙터 창에 보이게 하고 싶을때



public 

- Used whenever another script needs to access a variable.

다른 스크립트가 변수에 접근해야 할때



Auto properties 

- Used whenever you need different access modifies on the set or get properties.

자동: (?) get set 접근 수정이 필요할 때
(private get; set; 이런거 말하는 건가)


Explicit properties 

- Used whenever you need to get clever. For example data validation, triggering on change events, complex setting or getting behaviour.
명시적: 데이터 검증, 이벤트 트리거 등 값을 넣을 때 처리가 필요하거나, 데이터 바인딩할 것이라면



Method 

- Used whenever there are additional side effects above and beyond setting and getting a variable.
변수 get set 하면 부작용 있을 때



And there are a couple of bad practices you should stomp out mercilessly: 하면 병신짓

Using a public variable just to expose it to the inspector. 인스펙터에 그냥 보이려고 public 쓰기

Using auto properties on everything, regardless of need. 안 필요한데 무지성 자동 프로퍼티 쓰기