Quantcast
Channel: Questions in topic: "unit"
Viewing all articles
Browse latest Browse all 68

Adding to a public list from a script on another object.

$
0
0
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 FriendlyUnitsOrder; void Start () { FriendlyUnitsOrder= new List(); } } **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().FriendlyUnitsOrder.Add(this.gameObject); } } Thanks in advance for any help.

Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>