简体   繁体   中英

Can I use pre processor directives in Unity to differentiate debug and release mode

I want to create a level-based game with Unity. Let's assume you unlock the next level after finishing the previous one. Maybe some levels are locked until you find some items.

How would you test specific parts of your game? Let's say world 3 level 8 contains a part with a cave where the player has to jump over multiple obstacles. How would you test this cave scenario over and over again without restarting the level? I don't mean testing your application with Unit tests. Maybe you want to try out a specific mechanic and a specific spot in a specific level fits best for your tests.

Of course, you could prepare a save game or add some cheat code like "press + to skip this level" but I think the cheat code would be the worst idea because you would have to remove all these lines before releasing your game (and on each next release).

When developing with C# and Visual Studio it's possible to add preprocessor-directives . Does something similar exist for game development, especially for Unity?

Yes. You may define them in Scripting Define Symbols , accessible from:

Edit -> Project Settings -> Player -> Other Settings -> Scripting Define Symbols

From the manual you may also find the most useful directives already implemented in unity.

They are mostly used for platform dependent compilation, but they can be used also to differentiate between editor and real application.

For example #if UNITY_EDITOR will run the code just if you're in the unity editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM