Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Best Ways to organize variables?

Discussion in 'Scripting' started by MJSTCFLPS, Mar 8, 2017.

  1. MJSTCFLPS

    MJSTCFLPS

    Joined:
    Mar 8, 2017
    Posts:
    2
    Hi all,

    I like to make my scripts organized and easy to read, but I've got too many variables lying around and the inspector has become clustered and disorganized; so I'm trying to find a way to tidy up my variables but no on line documentation has been able to help me.

    I'm looking for a way to categorize my variables and put them under a collapsible menu. So I created different classes for different types of variables, like this:

    Code (CSharp):
    1.    
    2. [System.Serializable]
    3.     public class ShootVariables : System.Object {
    4.         //My variables go here
    5.     }
    6.     public ShootVariables shootVariables = new ShootVariables();
    7.  
    But every time I need to reference to variables inside that class, I have to first make reference to that class, which is not very efficient:

    Code (CSharp):
    1.  
    2. shootVariables.damage = 5f;
    3. recoilVariables.kickAmount = .5f
    Is there a way to just use the variables without referencing the class?
    I feel like I might be doing something wrong; Or could there be a different ways to create the collapsible menu? Or just a different way to organize your variables?

    Thanks
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Your scripts shouldn't have that many variables. If you're getting large amounts of them, then you might be having a single script do way too much.

    If you're talking about game settings, in that case I usually implement them in a ScriptableObject, and make that object a Singleton that loads the ScriptableObject and serves out the values in a global manner.
     
  3. booiljoung

    booiljoung

    Joined:
    May 12, 2013
    Posts:
    57
    Hi There

    No one seems to be able to answer your question. No one can know your intent specifically. The scope of the question should be reduced.

    Cheers!