- Home /
How to store TYPE variables names into an Array, and assign values to them.
I want to store a list of variable NAMES into an array, then make another array with type values (not references) of all kinds (int, string, bool etc), assign the values to the respective variable name and then call it. My code is not working. It gives me Null when I try to print the variable "name", where it should print "fff".
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class fClass: MonoBehaviour
{
public static int food;
public static string name;
public static int value;
public ArrayList vars = new ArrayList{food,name,value};
public ArrayList score = new ArrayList{3,"fff",98};
void Start(){
for(int i=0; i<score.Count; i++){
vars[i]=score[i];
}
Debug.Log (name);
}
}
Comment
It works nothing like that. Check out this http://msdn.microsoft.com/en-us/library/f7ykdhsy(v=vs.110).aspx
Your answer
![](https://koobas.hobune.stream/wayback/20220613135048im_/https://answers.unity.com/themes/thub/images/avi.jpg)