/// <summary> Constructor </summary> public Player(string _playerName, GameMaster.ControllerTypes _controllerType, Tower _towerPrefab, Vector3 _towerPosition, int _startingLevel, float _startingLevelProgress) { playerName = _playerName; controllerType = _controllerType; // Create tower tower = GameObject.Instantiate(_towerPrefab); tower.basePosition = _towerPosition; switch (controllerType) { case GameMaster.ControllerTypes.KeyboardWASD: { TowerControlKeyboard controller = tower.gameObject.AddComponent <TowerControlKeyboard>(); tower.controller = controller; controller.Init(KeyCode.A, KeyCode.D, KeyCode.W, KeyCode.S, KeyCode.Space); } break; case GameMaster.ControllerTypes.KeyboardArrows: { TowerControlKeyboard controller = tower.gameObject.AddComponent <TowerControlKeyboard>(); tower.controller = controller; controller.Init(KeyCode.LeftArrow, KeyCode.RightArrow, KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.Return); } break; case GameMaster.ControllerTypes.Gamepad: tower.controller = tower.gameObject.AddComponent <TowerControlGamepad>(); break; default: throw new UnityException("Unhandled Controller Type " + controllerType); } // Create HUD hud = UIMaster.instance.hud.AddPlayerHUD(playerName); SetScore(0); startingLevelProgress = _startingLevelProgress; levelMax = GameMaster.Tuning.levelMax; SetLevel(_startingLevel, true); SetState(States.Gameplay); }
/// <summary> Switches to the next control type </summary> /// <param name="_playerIdx"> Player index (0 = P1, etc) </param> /// <param name="_textLabel"> UI Text label to update </param> void ChangePlayerControls(int _playerIdx, Text _textLabel) { GameMaster.ControllerTypes controllerType = GameMaster.instance.ChangePlayerControls(_playerIdx); _textLabel.text = controllerType.ToString(); }