Search code examples
unity-game-enginemonodevelop

Unity3D: Manage messy code


I am writing my main manager script for my game. I seems like the script handles 10+ huge if..else..if..else statements. It looks messy and hard to manage. And in monodevelop I am not able to minimise particular parts of code like we can do in eclipse.

I am considering of creating individual script for each part and enable-access-disable it from a common script.

Please direct me to the better ways to do?


Solution

  • In the best case every method or class should have one responsibility, and only one.

    • Try to extract duplicate code into methods
    • Try to split up your classes, so that each class does only one thing
    • Advanced: organize your classes in layers (Model-View-Control) and only talk to other classes through interfaces