Working with Lists in Unity3d

I am looking for help working with List<> and I am hoping that somebody can give a short explanation of all the points that I am asking.

a) In the tutorials online, I keep seeing how to initialize a new List, such as:

List< int > Level = new List< int >();

However, I don’t see an explanation for a List<> declaration (assuming I created a List<> on my character script beforehand and want to continue using data I saved earlier). It appears to me that initializing a new List would effective create something new, not continue the data I saved earlier. How would I bring back my data from a previous instance of my game inside a List variable???

b) During game testing with Scene and Console how do I used Debug.Log to show all the saved data I have in my List variable??? Or simply, how can I view all the data inside my List in the editor if I make it a public variable??

c) Let’s say I want to create a List that holds 2 pieces of information, like

(Player Level) and (ExperiencePointsToNextLevel)

Do I have to make both of them int variables or can I have one float and one int variable??? How would I declare something like that??


I am not sure what you mean

If you want all objects share one list, you can make it static.

static List< int > Level = new List< int >();

you need a for-loop

string result = "";
for(int i = 0 ; i< Level.Count;i++){
result +=Level*+",";*

I suggest you not to use List
int level;
float exp4nextLevel;
or you can use Hashtable, but you will have to remember the type and purpose of each value by yourself, which is not very convenient.