C#에서 인터페이스는 일종의 계약서 같은 개념으로, 클래스나 구조체가 반드시 구현해야 할 메서드, 속성, 이벤트 또는 인덱서의 목록을 정의한다. 인터페이스는 구현 방법이 아니라 어떤 기능을 제공해야 하는지를 규칙처럼 정의한다.
public enum State {
Ready,
Empty,
Reloading
}// 상태 설정
State gunState;
gunState = State.Ready;
gunState = State.Empty;
gunState = State.Reloading;
유니티의 코루팀 메서드는 대기 시간을 가질 수 있는 메서드이다. 유니티에서 코루틴 메서드는 IEnumerator 타입을 반환해야 하며, 처리가 일시 대기할 곳에 yield 키워드를 명시해야 한다.
IEnumerator Clean() {
// clean A
yield return new WaitForSeconds(10f); // wait 10secs
// clean B
yield return new WaitForSeconds(20f); // wait 10secs
// clean C
}
코루틴 메서드는 StartCoroutine() 메서드로 실행한다.
StartCoroutine(Clean());
yield return new WaitForSeconds(10f);yield return null;StartCoroutine(Clean());StartCoroutine("Clean");