using UnityEngine;
using System.Collections;
public class People{
public string name;
public int type;
}
public class Game{
public ArrayList people;
public void start(){
People p = new People();
p.name = "Vitor";
p.type = 1;
people = new ArrayList ();
people.add(p);
Debug.Log(p[0].name);
}
}
Returned error:
Type 'object' does not contain a definition for 'name' and no extension method 'name' of type 'object' could be found (are you missing a using directive or an assembly reference?)
The ArrayList
is comprised of objects, so you need to cast it:
Debug.Log(((People)people[0]).name);
It should be Debug.Log((people[0] as People).name);
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With