//Update is called once per frame void Update() { if (player == null) { player = GameControl.GetPlayer(); if (player == null) { return; } } if (player.IsDestroyed()) { return; } if (joystickMove.GetMagnitude() > 0) { player.Move(joystickMove.GetValue()); } if (joystickAim.GetMagnitude() > 0) { player.AimTurretDPad(joystickAim.GetValue()); player.FireWeapon(); } }
public void UpdateInputMode(UnitPlayer _Player, ControllerPlayer _Controller) { m_Direction = E_Direction.None; if (Input.GetKey(KeyCode.Z)) { m_Direction = E_Direction.North; } if (Input.GetKey(KeyCode.S)) { m_Direction = E_Direction.South; } if (Input.GetKey(KeyCode.D)) { m_Direction = E_Direction.East; } if (Input.GetKey(KeyCode.Q)) { m_Direction = E_Direction.West; } if (_Player.CanMove()) { if (m_Direction != E_Direction.None) { I_Unit unitOnTile = _Player.GetTile().GetNeighbour(m_Direction).GetUnit(); if (_Player.CanMoveTo(m_Direction)) { _Player.Move(m_Direction); TurnOrder.StartAllUnitsTurn(); } else if (unitOnTile is UnitEnemy) { _Player.SetAttackingEnemy(unitOnTile as UnitEnemy); } else { _Player.TurnToward(m_Direction); } } } _Controller.SetAnimatorBool("IsMoving", _Player.IsMoving()); }
void Update() { if (!enableMouseNKeyInput) { return; } if (Input.GetButtonDown("Cancel") || Input.GetKeyDown(KeyCode.Escape) && !GameControl.IsGameOver()) { _TogglePause(); } //if(Input.GetKeyDown(KeyCode.C) && !GameControl.IsGameOver()) ToggleLevelPerkMenu(); /* * if(Input.GetKeyDown(KeyCode.Q)){ * Debug.Log("Paused for screen shot. Fire from UIMainControl"); * if(Time.timeScale==1) Time.timeScale=0; * else Time.timeScale=1; * } */ if (GameControl.IsGamePlaying()) { UnitPlayer player = GameControl.GetPlayer(); if (player != null && !player.IsDestroyed() && Input.touchCount == 0) { //Debug.Log("Fire!! "+Time.time); //movement if (Input.GetButton("Horizontal") || Input.GetButton("Vertical")) { player.Move(new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")), Input.GetKey(KeyCode.LeftShift)); } //brake if (Input.GetKey(KeyCode.Space)) { player.Brake(); } //switch weapon if (Input.GetAxisRaw("Mouse ScrollWheel") != 0 && scrollCD <= 0) { player.ScrollWeapon(Input.GetAxis("Mouse ScrollWheel") > 0 ? 1 : -1); scrollCD = 0.15f; } scrollCD -= Time.deltaTime; string[] names = Input.GetJoystickNames(); bool hasJoystick = names.Length > 0 ? true : false; //turret facing //player.AimTurretMouse(Input.mousePosition); //player.AimTurretDPad(Input.mousePosition-new Vector3(Screen.width/2, Screen.height/2)); if (Input.GetButton("RightThumbStick_X") || Input.GetButton("RightThumbStick_Y")) { player.AimTurretDPad(new Vector2(Input.GetAxisRaw("RightThumbStick_X"), Input.GetAxisRaw("RightThumbStick_Y"))); } else if (!hasJoystick) { player.AimTurretMouse(Input.mousePosition); } //fire bool continousFire = player.ContinousFire() & (Input.GetMouseButton(0) || Input.GetButton("Fire1")); if (Input.GetMouseButtonDown(0) || Input.GetButtonDown("Fire1") || continousFire) { player.FireWeapon(); } //alt fire, could fire weapon alt-mode to launch selected ability if (Input.GetMouseButtonDown(1) || Input.GetButtonDown("Fire2")) { player.FireAbility(); } //launch ability if (Input.GetMouseButtonDown(2) || Input.GetButtonDown("Fire3")) { player.FireAbilityAlt(); } //reload if (Input.GetKeyDown(KeyCode.R) || Input.GetButtonDown("Jump")) { player.Reload(); } //bring up the chracter & perk menu if (UILevelPerkMenu.Enabled() && Input.GetKeyDown(KeyCode.C)) { ToggleLevelPerkMenu(); } } } }
public void UpdateInputMode(UnitPlayer _Player, ControllerPlayer _Controller) { if (Input.touchCount >= 1) { Touch touch = Input.touches[0]; if (!m_HasStartedSwipe) { m_HasStartedSwipe = true; m_SwipeStartPosition = touch.position; } UserInterface.DisplayMovementLine(m_SwipeStartPosition, touch.position); if (touch.phase == TouchPhase.Canceled) { m_HasStartedSwipe = false; UserInterface.HideMovementLine(); } else if (touch.phase == TouchPhase.Ended) { Vector2 swipeDirection = touch.position - m_SwipeStartPosition; if (swipeDirection.sqrMagnitude > 100) { if (Mathf.Abs(swipeDirection.x) > Mathf.Abs(swipeDirection.y)) { if (swipeDirection.x > 0) { m_DirectionBuffer = E_Direction.East; } else { m_DirectionBuffer = E_Direction.West; } } else { if (swipeDirection.y > 0) { m_DirectionBuffer = E_Direction.North; } else { m_DirectionBuffer = E_Direction.South; } } } m_HasStartedSwipe = false; UserInterface.HideMovementLine(); } } if (_Player.CanMove()) { if (m_DirectionBuffer != E_Direction.None && _Player.CanMoveTo(m_DirectionBuffer)) { m_MovingDirection = m_DirectionBuffer; m_DirectionBuffer = E_Direction.None; } if (m_MovingDirection != E_Direction.None) { I_Unit unitOnTile = _Player.GetTile().GetNeighbour(m_MovingDirection).GetUnit(); if (_Player.CanMoveTo(m_MovingDirection)) { _Player.Move(m_MovingDirection); TurnOrder.StartAllUnitsTurn(); } else if (unitOnTile is UnitEnemy) { _Player.SetAttackingEnemy(unitOnTile as UnitEnemy); } else { m_MovingDirection = E_Direction.None; } } } _Controller.SetAnimatorBool("IsMoving", _Player.IsMoving()); }