/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> private void Awake() { _rb = GetComponent <Rigidbody>(); _animator = GetComponent <Animator>(); _auxBlendValue = 0.0f; _staminaScript = GetComponent <Stamina>(); _flightMovement = new FlyBehaviour(); _walkMovement = new WalkingBehaviour(); _currMovement = _flightMovement; _flying = true; _model = transform.GetChild(0); Action += ChangeMovement; _playerController = new PlayerController(); _playerController.FlightActions.MovementControl.performed += ctx => _movementInput = ctx.ReadValue <Vector2>(); _playerController.FlightActions.LiftOff.performed += ctx => ChangeMovement(); }
/// <summary> /// Method to change the current movement /// </summary> private void ChangeMovement() { Vector3 auxRotation; _flying = !_flying; if (_flying) { auxRotation = _currMovement.Rotation; auxRotation.x = -20.0f; _currMovement = _flightMovement; _currMovement.Rotation = auxRotation; _rb.useGravity = false; } else { auxRotation = _currMovement.Rotation; auxRotation.x = 0.0f; _currMovement = _walkMovement; _model.localRotation = Quaternion.identity; _currMovement.Rotation = auxRotation; _rb.useGravity = true; } }