Hi there, I have an attributes script for each of my charactors, which contains a selection of attribute floats for that character, and a list containing all the affor mentioned floats. This looks something like this:
public class Attributes : MonoBehaviour {
public List<float> attributesList = new List<float> ();
public float attribute01;
public float attribute02;
public float attribute03;
void Start () {
attributesList.Add (attribute01);
attributesList.Add (attribute02);
attributesList.Add (attribute03);
}
}
The rest of my scripts often reference these attributes directly via the floats rather than the list (which is the way I want to keep it if I can to stop the code getting too messy) but there is one infrequent circumstance in which I need to randomly select an attribute via the list to alter it.
I have been trying it out as is, and currently altering a list entry doesn’t alter the corresponding float, so it is clear that the list currently isn’t a list of refernces. After some research through unity and c# documentation, I have tried inserting the word “ref” in places to see if that will help, but unity doesn’t like what I have tried so far.
How then, can I build the list from references rather than the corresponding floats? As I said earlier, I would rather avoid having to use only the list throughout the game.
Thanks in advance,
Pete