以下の例では、条件付きでコンパイルしたコードをテストする方法を示します。また、ターゲットビルドに選択されたプラットフォームに基づいてメッセージを出力します。
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 のメッセージが表示されます。