Search Unity

A Question About Static Variables

Discussion in 'Scripting' started by Afropenguinn, Oct 24, 2014.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    I have a dictionary of abilities which each refer to classes. This way I can set a characters ability slot (think like in an MMO) by simply going ability[0] = abilityList["Shoot"]. I didn't want every character to contain a copy of this list, but I wanted them all to have access to it. All character derive from the same class. Is a static variable appropriate for this situation? Also, when I have it create these static variables what happens if i have multiples of that objects, is the variable only created and set once?
     
    Last edited: Oct 24, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, a static variable means there can only ever be one instance of it.

    --Eric
     
  3. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Alright, thank you very much!