Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Ouya Unity Game Development

You're reading from  Ouya Unity Game Development

Product type Book
Published in Oct 2013
Publisher Packt
ISBN-13 9781783559701
Pages 118 pages
Edition 1st Edition
Languages
Author (1):
Gary Riches Gary Riches
Profile icon Gary Riches

Platform Dependent Compilation


Unity includes a feature called Platform Dependent Compilation. It consists of some preprocessor directives that let you partition your scripts to compile and execute sections of code for one of the supported platforms. This functionality is also supported within Editor, so you can compile the code specifically for your mobile or console and test it in Editor.

This is useful if you're branching code for things, such as In-App Purchase or control mechanisms. To use the Platform Dependent Compilation feature, you use the pound or hash symbol, as shown in the following code:

void Start () {
  
  #if UNITY_EDITOR
    Debug.Log("Unity Editor");
  #endif
  
  #if UNITY_ANDROID
    Debug.Log("Android");
  #endif
  
  #if UNITY_IPHONE
    Debug.Log("iPhone");
  #endif
  
  #if UNITY_STANDALONE_OSX
    Debug.Log("Stand Alone OSX");
  #endif
  
  #if UNITY_STANDALONE_WIN
    Debug.Log("Stand Alone Windows");
  #endif
}

While this is brilliant for coding between platforms...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}