/// <summary>Spawn avatar if spawn point is registered</summary> /// <param name="playerNo">Number of the avatar to spawn</param> /// <param name="active">If true, the avatar is spawned active</param> /// <param name="allowControl">If true, the avatar is immediately controllable</param> public GameObject SpawnCharacter(int playerNo, bool allowControl = true) { Transform spawnTr = spawnPoints[playerNo - 1]; if (spawnTr == null) { throw ExceptionsUtil.CreateExceptionFormat("No spawn point registered for player {0}.", playerNo); } // activate stored avatar instance and move to spawn position CharacterMaster avatar = m_Characters[playerNo - 1]; avatar.gameObject.SetActive(true); avatar.transform.position = spawnTr.position; // stop control if needed (prefab should have CharacterControl active by default) if (!allowControl) { avatar.GetComponentOrFail <CharacterControl>().StopControl(); } // update derivated counter of avatars registered and active in the scene remainingCharacterNb++; // return the spawned avatar as a game object return(avatar.gameObject); }
private void SpawnPlayerCharacter() { // Spawn Player Character if (m_PlayerSpawnTransform != null) { // Spawn character as a pooled object (in a pool of 1 object) m_playerCharacterMaster = PlayerCharacterPoolManager.Instance.SpawnCharacter(m_PlayerSpawnTransform.position); // Assign HUD's player health gauge to player health system (on Restart, it only refreshes the gauge) var healthSystem = m_playerCharacterMaster.GetComponentOrFail <HealthSystem>(); HUD.Instance.AssignGaugeHealthPlayerTo(healthSystem); } }