#if UNITY_IOS - disables everything in Visual Studio
Hi, I have no idea what's going on, but when I use platform dependant compilation Video Studio goes nuts.
I set up this super simple bit of code in a class:
Vector3 motion = new Vector3();
#if UNITY_EDITOR || UNITY_STANDALONE
motion.x = Input.GetAxisRaw("Horizontal");
motion.y = 0f;
motion.z = Input.GetAxisRaw("Vertical");
#endif
#if UNITY_IOS
motion.x = Input.acceleration.x;
#endif
but while I'm in between "#if UNITY_IOS" and "#endif" Visual Studio just gives up, it greys out everything, disables all auto-completion and acts like I'm writing a comment. See image (line-number 20). How can I develop code for iOS without VS going bonkers? I am using macOS.
Answer by Hellium · Dec 10, 2017 at 04:49 PM
UNITY_STANDALONE
will be evaluated to true
when you have selected the Windows / Mac OS in your build settings.
UNITY_IOS
will be evaluated to true
when iOS is selected in your build settings.
So I can only code properly when I change the build settings in Unity? Is there a point to that?
There is an other alternative, which is less efficient than the preprocessor directives. Application.platform will return the platform the game is running on. Your code won't be greyed out like if you use preprocessor directives.
I empathise with you, I've never been able to solve this problem. Here are two possible workarounds :
1. Put your iOS-only code outside of those directives so that you have auto-completion, and when you want to test, put the code back between the directives
2. Put your IOS-only code inside a function (outside the preprocessor directives) and call the function between the preprocessor directives.
I like your option 2, makes for fairly clean code. Na$$anonymous$$g the methods to reflect what platform will run them then also helps to improve legibility… Thank you!
Your answer
Follow this Question
Related Questions
Buttons not firing unless held down for a while. 0 Answers
Visual Studio for Mac External Drive Sharing Violation 1 Answer
Should I leave space for Ad's while designing my game?Also how are they implemented? 0 Answers
My object disappears when being dragged through the screen 0 Answers
How to send notifications while the game is closed? 2 Answers