how to access lists dynamically?

Hey friendos, newbie question here;
I’m currently using a list to store data for each weapon the player can use, but iI don’t know how to reference it efficiently. my current setup is;

[System.Serializable]
public class Weaponz{    //creates list with data of every weapon
    public string name;
    public float placeholderStat1, placeholderStat2;
   
}
[ExecuteInEditMode]
public class Test : MonoBehaviour
{
    public List<Weaponz> weapons_Info;
   
    public Weaponz pistol = new Weaponz(), shotgun = new Weaponz();
    public float activeweapon;
   
    public float currentPlaceholderStat1, currentPlaceholderStat2; //active memory of weapon
   
    void Start()            //change weapon stats
    {               
        if(activeweapon == 1){
           
            currentPlaceholderStat1 = pistol.placeholderStat1;
            currentPlaceholderStat2 = pistol.placeholderStat2;
        }
       
        if(activeweapon == 2){           
            currentPlaceholderStat1 = shotgun.placeholderStat1;
            currentPlaceholderStat2 = pistol.placeholderStat2;
        }
    }
}

basically I want to be able to pull variables in one function, if that makes sense?
thanks!

You may wish to consider reaching for ScriptableObjects for this.

For runtime modified data you can always Instantiate() a fresh transient copy of the weapon SO from the base original stats.

ScriptableObject usage in RPGs:

Usage as a shared common data container:

2 Likes

i did that, works great! thanks dude!