using System.Collections.Generic; using UnityEngine; public class Populate : MonoBehaviour { public GameObject target; public bool setTargetsActive; public bool includeTargetInList = true; public int times = 5; public List DoPopulate() { List list = new List(); if (includeTargetInList) { list.Add(target); } for (int i = 0; i < times; i++) { GameObject gameObject = Object.Instantiate(target, target.transform.position, base.transform.transform.rotation, base.transform); gameObject.transform.localScale = target.transform.localScale; list.Add(gameObject); if (setTargetsActive) { gameObject.SetActive(value: true); } } return list; } public List DoPopulate(bool addComponentIfMissing = true) where T : MonoBehaviour { List list = new List(); if (includeTargetInList && target != null) { T val = target.GetComponent(); if ((Object)val == (Object)null && addComponentIfMissing) { val = target.AddComponent(); } if (!((Object)val != (Object)null)) { Debug.LogError("Could not find component"); return null; } list.Add(val); } for (int i = 0; i < times; i++) { GameObject gameObject = Object.Instantiate(target, target.transform.position, base.transform.transform.rotation, target.transform.transform.parent); gameObject.transform.localScale = target.transform.localScale; T val2 = gameObject.GetComponent(); if ((Object)val2 == (Object)null && addComponentIfMissing) { val2 = gameObject.AddComponent(); } if ((Object)val2 != (Object)null) { list.Add(val2); } if (setTargetsActive) { gameObject.SetActive(value: true); } } return list; } }