/// <summary> /// Adds the player spawn point, using the position and rotation of the given transform as the spawnpoint position/rotation /// </summary> /// <param name="playerId">Player identifier.</param> /// <param name="targetSpawnPoint">Target spawn point transform.</param> public void AddPlayerSpawnPoint(System.Guid playerId, Transform targetSpawnPoint) { //If the dictionary doesn't have the key, we need to add it if (!playerSpawnDictionary.ContainsKey(playerId)) { playerSpawnDictionary.Add(playerId, new SmartPlayerSpawnPoint(targetSpawnPoint.position, targetSpawnPoint.rotation.eulerAngles)); } else { SmartPlayerSpawnPoint newPlayerSpawnPoint = playerSpawnDictionary[playerId]; newPlayerSpawnPoint.playerSpawnPosition = targetSpawnPoint.position; newPlayerSpawnPoint.playerSpawnRotation = targetSpawnPoint.rotation.eulerAngles; playerSpawnDictionary[playerId] = newPlayerSpawnPoint; } }
/// <summary> /// Adds the player spawn point, using the given spawn position & no rotation /// </summary> /// <param name="playerId">Player identifier.</param> /// <param name="spawnPosition">Spawn position.</param> /// <param name="spawnRotation">Spawn rotation.</param> public void AddPlayerSpawnPoint(System.Guid playerId, Vector3 spawnPosition) { //If the dictionary doesn't have the key, we need to add it if (!playerSpawnDictionary.ContainsKey(playerId)) { playerSpawnDictionary.Add(playerId, new SmartPlayerSpawnPoint(spawnPosition, Vector3.zero)); } else { SmartPlayerSpawnPoint newPlayerSpawnPoint = playerSpawnDictionary[playerId]; newPlayerSpawnPoint.playerSpawnPosition = spawnPosition; newPlayerSpawnPoint.playerSpawnRotation = Vector3.zero; playerSpawnDictionary[playerId] = newPlayerSpawnPoint; } }
/// <summary> /// Spawns the player. /// </summary> /// <param name="playerId">Player identifier.</param> public void SpawnPlayer(System.Guid playerId) { if (HasPlayerSpawnPoint(playerId)) { //Spawn the player prefab SmartPlayerSpawnPoint playerSpawnInfo = playerSpawnDictionary[playerId]; Vector3 spawnPosition = playerSpawnDictionary[playerId].playerSpawnPosition; Quaternion spawnRotation = Quaternion.Euler(playerSpawnInfo.playerSpawnRotation); GameObject.Instantiate(playerPrefabToSpawn, spawnPosition, spawnRotation); } else { Debug.LogWarning("No player spawn point found for guid: " + playerId.ToString()); } }
/// <summary> /// Adds the player spawn point, using the given spawn position & rotation /// </summary> /// <param name="playerId">Player identifier.</param> /// <param name="spawnPosition">Spawn position.</param> /// <param name="spawnRotation">Spawn rotation.</param> public void AddPlayerSpawnPoint(System.Guid playerId, float spawnPositionX, float spawnPositionY, float spawnPositionZ, float spawnRotationX, float spawnRotationY, float spawnRotationZ) { //If the dictionary doesn't have the key, we need to add it Vector3 spawnPosition = new Vector3(spawnPositionX, spawnPositionY, spawnPositionZ); Quaternion spawnRotation = Quaternion.Euler(new Vector3(spawnRotationX, spawnRotationY, spawnRotationZ)); if (!playerSpawnDictionary.ContainsKey(playerId)) { playerSpawnDictionary.Add(playerId, new SmartPlayerSpawnPoint(spawnPosition, spawnRotation.eulerAngles)); } else { SmartPlayerSpawnPoint newPlayerSpawnPoint = playerSpawnDictionary[playerId]; newPlayerSpawnPoint.playerSpawnPosition = spawnPosition; newPlayerSpawnPoint.playerSpawnRotation = spawnRotation.eulerAngles; playerSpawnDictionary[playerId] = newPlayerSpawnPoint; } }