다음 예시는 조건부로 컴파일된 코드를 테스트하는 방법을 보여 줍니다. 또한 타겟 빌드에 대해 선택한 플랫폼에 따라 메시지를 출력합니다.
using UnityEngine;
using System.Collections;
public class PlatformDefines : MonoBehaviour {
void Start () {
#if UNITY_EDITOR
Debug.Log("Unity Editor");
#endif
#if UNITY_IOS
Debug.Log("Unity iOS");
#endif
#if UNITY_STANDALONE_OSX
Debug.Log("Standalone OSX");
#endif
#if UNITY_STANDALONE_WIN
Debug.Log("Standalone Windows");
#endif
}
}
Unity Editor와 Unity iOS 메시지가 콘솔에 나타납니다.