unity 判断平台(安卓,iOS还是编辑器)

两种方式

————— C预处理器编译判断 —————

#if UNITY_IOS
// ... iOS项目才会编译
#elif UNITY_ANDROID
// ... apk 或 iOS项目才会编译
#elif UNITY_EDITOR
// ... UNITY调试时候才编译
#endif

 

————— 代码运行时判断 —————

if(Application.platform == RuntimePlatform.Android)
{
//只有在安卓生效
}

 

:)