void Awake() { // Set up references text = this.GetComponentInChildren <Text>(); canvas = this.GetComponentInChildren <Canvas>(); PlayerController playerController = GetComponentInParent <PlayerController>(); playerType = playerController.playerType; }
private void CreatePlayerController(int playerIndex, PlayerController.PlayerType playerType) { GameObject associatedPlayer = PlayerObjects[playerIndex]; if (associatedPlayer == null) { Debug.LogWarning("The Associated Player is null. Perhaps no characters were added to the game"); return; } GameObject playerControllerGameObject = new GameObject(); PlayerController playerController; switch (playerType) { case PlayerController.PlayerType.Local: playerController = playerControllerGameObject.AddComponent <LocalPlayerController>(); playerController.PlayerIndex = playerIndex; break; case PlayerController.PlayerType.Remote: playerController = playerControllerGameObject.AddComponent <RemotePlayerController>(); playerController.PlayerIndex = playerIndex; break; case PlayerController.PlayerType.AI: playerController = playerControllerGameObject.AddComponent <LocalPlayerController>(); playerController.PlayerIndex = playerIndex; // TO DO : Replace with AI Controller break; default: playerController = playerControllerGameObject.AddComponent <LocalPlayerController>(); break; } playerController.CommandInterpreter = associatedPlayer.GetComponent <CommandInterpreter>(); playerController.InteractionHandler = associatedPlayer.GetComponent <CharacterInteractionHandler>(); playerController.CharacterStats = associatedPlayer.GetComponent <CharacterStats>(); playerController.CharacterStats.PlayerIndex = playerIndex; if (IsNetworkedMode && playerType == PlayerController.PlayerType.Local) { playerController.gameObject.AddComponent <NetworkInputHandler>(); } playerControllerGameObject.transform.parent = this.gameObject.transform; playerControllerGameObject.name = PlayerControllerString + (playerIndex + 1); if (Players.Count > playerIndex + 1) { Players[playerIndex] = playerController; } else { Players.Add(playerController); PlayerMatchStatistics stats = new PlayerMatchStatistics(); stats.PlayerIndex = playerIndex; PlayerMatchStats.Add(stats); } }