- Home /
#if UNITY ?
I see a number of preprocessor symbols listed at http://unity3d.com/support/documentation/Manual/Platform%20Dependent%20Compilation.html, but I don't see a catch-all UNITY symbol.
I would like to share some C# source code between Unity and a Visual Studio project, but would prefer there to be a UNITY symbol I can #if against for in Unity/MonoDevelop. Am I not seeing a known symbol, or is there a way to add this symbol to both Unity and MonoDevelop?
Answer by Louis Watson · Sep 21, 2014 at 07:42 PM
just define a symbol like so:
#define UNITY
put that in a script just for unity and drop it in Inspector for Script Execution Order.
Make sure the script element in the inspector goes above the Default Time area using drag n drop. Then you can check like so in the rest of your scripts:
#if (UNITY)
... your code
#endif
Answer by Vjosey · Mar 16, 2016 at 05:46 PM
Here is a list of them. http://docs.unity3d.com/Manual/PlatformDependentCompilation.html
Answer by MoonCrowned · Mar 29, 2019 at 12:55 PM
#if UNITY_5_3_OR_NEWER
works best for me. It is defined everywhere from Unity5.3.0 (surprise!)