KaiClavier

HideOnPlatforms.cs

Feb 1st, 2021 (edited)
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. //Copyright (c) 2021 Kai Clavier [kaiclavier.com] Do Not Distribute
  2. using UnityEngine;
  3. /*
  4. Destroys the gameObject this script is attached to if it's not meant to appear on it.
  5. Remember that switching target platform in unity will effect this check.
  6. */
  7. public class DestroyOnPlatforms : MonoBehaviour
  8. {
  9.    
  10.     public bool editor = true;
  11.     [Header("Show on these platforms:")]
  12.     public bool win = true;
  13.     public bool mac = true;
  14.     public bool linux = true;
  15.     public bool web = true;
  16.     public bool android = true;
  17.     public bool ios = true;
  18.  
  19.     void Awake()
  20.     {
  21.         #if UNITY_EDITOR
  22.         if(!editor)
  23.         {
  24.             DestroyImmediate(this.gameObject);
  25.             return;
  26.         }
  27.         #endif
  28.  
  29.         #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
  30.         if(!mac) DestroyImmediate(this.gameObject);
  31.         #elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
  32.         if(!win) DestroyImmediate(this.gameObject);
  33.         #elif UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
  34.         if(!linux) DestroyImmediate(this.gameObject);
  35.         #elif UNITY_WEBGL
  36.         if(!web) DestroyImmediate(this.gameObject);
  37.         #elif UNITY_ANDROID
  38.         if(!android) DestroyImmediate(this.gameObject);
  39.         #elif UNITY_IOS
  40.         if(!ios) DestroyImmediate(this.gameObject);
  41.         #endif
  42.     }
  43. }
Add Comment
Please, Sign In to add comment