- Home /
This post has been wikified, any user with enough reputation can edit it.
List <> Problem :(
> using UnityEngine;
> using System.Collections;
> [System.Serializable]
> public class pl
> { public string name; public int
> hp,maxhp; public int attack; }
> using UnityEngine;
> using System.Collections;
> using System.Collections.Generic;
> public class player : MonoBehaviour {
> public pl[] pl; public List pll;
>
> void Update(){
>
> } void OnGUI(){
> if(GUILayout.Button("TIKLA")){
> pll.Add(pl[0]);
>
> } } }
**
Sorry for very bad english :( When I add list same item.
When I change the name of the last item Change is happening as I have all of the same item I want to be independent of the items
Comment
Best Answer
Answer by nesis · Feb 15, 2014 at 07:38 AM
You declare and instantiate a list of MyClass objects like this:
List myList = new List();
For you, that'd be this:
public List pll = new List();
If you're declaring it as a member variable, you won't delete any elements by doing what I'm suggesting:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class SomeSerializedClass {
float someFloat;
string someString;
}
public class $$anonymous$$yScript : $$anonymous$$onoBehaviour {
public List<SomeSerializedClass> someSerializedClassList = new List<SomeSerializedClass>();
public SomeSerializedClass[] someSerializedClassArray;
void OnGUI() {
if(GUILayout.Button("TI$$anonymous$$LA")) {
someSerializedClassList .Add(someSerializedClassArray[0]);
}
}
}