最近一直在做一个小游戏,想让它在不同平台自适应,当然代码肯定要一次性写完啦,为了适应各种平台,大家肯定会使用条件编译了,下面就说说怎么使用条件编译,条件编译不难,关键是大家不知道它的名字。
void Awake () {
#if UNITY_ANDROID
the code of android
#endif
#if UNITY_IPHONE
the code of iphone
#endif
#if UNITY_WIN
the code of android
#endif
}
除了条件编译还可以进行平台判断;
通过Application.platform==RuntimePlatform.Android来判断平台,RuntimePlatform后面有很多平台,大家可以选择使用