0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Unity】プラットフォームごとに処理をわける

Posted at

UnityでOSごとに処理内容をわけるには?

UnityでOSごとに処理を分けたい場合に、どのようにコーディングするのかの一例が判明しましたので備忘録として残しておきます。

例)

  • 動作環境がAndroidのときはコンソールにHello Android.
  • iOSのとはコンソールにHello iOSを出力。
  • すべて同じメソッド上で実装。
SwitchRunEnv.cs
    void Start()
    {
#if UNITY_ANDROID //Androidの場合の処理
        Debug.Log("Hello Android");
#endif

#if UNITY_IOS //iOSの場合の処理
        Debug.Log("Hello iOS");
#endif
    }

説明

  • #ifで指定した条件に一致する処理は、#endifまでが実行されます。
  • #if#endifプリプロセッサディレクティブと呼ばれています。
  • プリプロセッサディレクティブは他にも#elif#regionなどがあります。気になる方は下記のリンクを参考に
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?