public UnitClass InstantiateUnit(Vector2 position, UnitSO unitSO, bool playerSide) { Vector3 pos = new Vector3(position.x * GridClass.instance.Offset, 0, position.y * GridClass.instance.Offset); Transform gO; // Unit's game object UnitClass unit = Instantiate(unitSO).unit; unit.FullHealth(); // If not given a prefab to instantiate, use the default one. if (unit.UnitGO == null) { gO = (Transform)Instantiate(defaultUnitPrefab.transform, pos, Quaternion.identity, this.transform); unit.UnitGO = gO.gameObject; } else { // gO = (Transform)Instantiate( unit.UnitGO.transform, pos, Quaternion.identity, this.transform ); Debug.Log("Unit Instantiation: Hello"); } Material mat = unit.UnitGO.transform.GetChild(0).GetComponent <Renderer>().material; if (playerSide == true) { mat.color = Color.blue; unit.PlayerSide = true; } else { mat.color = Color.red; unit.PlayerSide = false; } //InstantiateEquipment if (unit._weapon != null && unit._weapon._prefab != null) { Transform[] children = unit.UnitGO.transform.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if (child.name == "Weapon Point") { GameObject item = Instantiate(unit._weapon._prefab); item.transform.SetParent(child, false); } } } if (unit._armour != null && unit._armour._prefab != null) { Transform[] children = unit.UnitGO.transform.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if (child.name == "Armour Point") { GameObject item = Instantiate(unit._armour._prefab); item.transform.SetParent(child, false); } } } CellClass unitCell; unitCell = GridClass.instance.FindCellInArray(( CellClass c ) => c.GridPosition == position); if (unitCell != null) { unit.Cell = unitCell; unitCell.Occupied = true; } else { Debug.Log("Uh oh... MakeUnit malfunction"); } return(unit); }