Integrating GameObjects
Suppose your tactical RPG needs to show a complex model for each support member, made up of primitive or Prefab GameObjects. Further, each ally’s base class needs to keep track of its own component list and make each component part a child of a common parent when instantiated. Well, let’s not just suppose; let’s build that in!
Update the SupportAlly script to match the following code, which will now store a list of GameObjects, instantiate an empty parent object for each ally, and set new components as children of the parent whenever they’re added by our concrete builders:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SupportAlly
{
public string allyType;
// 1
public List<GameObject> components = new List<GameObject>();
// 2
public GameObject parent;
public SupportAlly(string newAlly)
{
allyType = newAlly;
parent ...