I’m trying to add to a public list from a script on another object. Eventually I want to have spawned units to be entered into a list so I can store which units are spawned in what order. This seems really simple, can anyone help?
This is the public list:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ExampleLister : MonoBehaviour
{
public List<GameObject> FriendlyUnitsOrder;
void Start ()
{
FriendlyUnitsOrder= new List<GameObject>();
}
}
This is the the script on the object I will eventually turn into a unit:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Unit_Default_Friendly : MonoBehaviour
{
void Start ()
{
gameObject.GetComponent<Mover>().FriendlyUnitsOrder.Add(this.gameObject);
}
}
Thanks in advance for any help.