private void Spawn() { Vector3 pos = GetLocalRandomSpawnPosition() + transform.position; GameObject go = _team.Instantiate(UnitPrefab, pos, transform.rotation); go.BroadcastMessage("SetWaypoint", _nearestWaypoint); OnUnitSpawned?.Invoke(this, go); }
private GameObject Spawn() { Vector3 basePos = SpawnRelativeToRoot ? _root.position : transform.position; Quaternion baseRot = SpawnRelativeToRoot ? _root.rotation : transform.rotation; Vector3 pos = GetLocalRandomSpawnPosition() + basePos; GameObject go = _team.Instantiate(SelectUnitPrefab(), pos, baseRot); OnUnitSpawned?.Invoke(this, go); return(go); }
protected GameObject PlaceUnit(GameObject prefab, Vector3 position, Quaternion rotation) { Unit u = prefab.GetComponent <Unit>(); GameObject go = TeamInfo.Instantiate(prefab, position, rotation); Unit placed = go.GetComponent <Unit>(); AssignCommander(go); _alivePlaced.Add(placed); go.GetComponent <Health>().OnDeath += OnUnitDeath; void OnUnitDeath() { u.GetComponent <Health>().OnDeath -= OnUnitDeath; _alivePlaced.Remove(placed); OnPlacedUnitDeath?.Invoke(this, u); if (_alivePlaced.Count == 0) { OnEliminated?.Invoke(this); } } return(go); }