ArrayList object. , . , ArrayList, People, .
, :
People first = (People) people[0];
Debug.Log(first.name);
( ):
Debug.Log(((People) people[0]).name);
With that said, you should use a type List<T>instead ArrayList. Of course, it protects your code from errors only by accepting the specified type Tas content, and when you access an element, it already has a type T. Your code rewritten with List<People>:
using UnityEngine;
using System.Collections.Generic;
public class People {
public string name;
public int type;
}
public class Game {
public List<People> people;
public void Start() {
People p = new People();
p.name = "Vitor";
p.type = 1;
people = new List<People>();
people.Add(p);
Debug.Log(p[0].name);
}
}
Note that now you do not need to highlight content when accessing with p[0].
source
share