- Home /
Count returning 0 when called outside object~
Oddly enough, I cant seem to call list.Count on "Waypoints" out side of the class?? Debug.Log (WaypointManager.Waypoints[0].name);
will return just fine on the PlayerScript class... but WaypointManager.Waypoints.count always returns 0 from the player script class
public class WaypointManager: MonoBehaviour {
public List<GameObject> Waypoints{get;set;}
void Start()
{
if(Waypoints == null){
Waypoints = new List<GameObject>();
}
}
...
}
public class PlayerScript : MonoBehaviour {
public WaypointManager WaypointManager{get;set;}
void Start () {
WaypointManager = GameObject.Find(this.transform.parent.name + "/WaypointManager").GetComponent<WaypointManager>();
}
public void Getcount(){
WaypointManager.Waypoints.count//Will always return 0
WaypointManager.Waypoints[0].name//Will return just fine
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
GameObject as a constraint for generic class 1 Answer
Classes and Scripting 2 Answers