How can I do a if statement with the new input system? I have it now that when the Right mouse button is clicked it allows for the mouse to control the camera… but when I release the right mouse button it still allows for the camera to be controlled and the bool is still listed as True.
private PlayerInputControls playerInputControls;
//Rotation variables
public bool _rightMouseDown = false;
private const float InternalRotationSpeed = 4;
private const float InternalMoveSpeed = 4;
private Quaternion _rotationTarget;
private Vector2 _mouseDelta;
private Vector3 _moveTarget;
[Tooltip("How fast the camera rotates")]
public float RotationSpeed;
void Awake()
{
playerInputControls = new PlayerInputControls();
}
private void Start()
{
//Set the initial rotation value
_rotationTarget = transform.rotation;
}
private void OnEnable()
{
playerInputControls.Player.Camera_Rotate_Toggle.performed += ToggleCam;
playerInputControls.Player.Camera_Rotate_Toggle.Enable();
playerInputControls.Player.Camera_Rotate.performed += OnRotate;
playerInputControls.Player.Camera_Rotate.Enable();
}
private void OnDisable()
{
playerInputControls.Player.Camera_Rotate_Toggle.performed -= ToggleCam;
playerInputControls.Player.Camera_Rotate_Toggle.Disable();
playerInputControls.Player.Camera_Rotate.performed += OnRotate;
playerInputControls.Player.Camera_Rotate.Disable();
}
private void ToggleCam(InputAction.CallbackContext context)
{
var value = context.ReadValue<float>();
_rightMouseDown = value >= 0.9f;
}
public void OnRotate(InputAction.CallbackContext context)
{
_mouseDelta = _rightMouseDown ? context.ReadValue<Vector2>() : Vector2.zero;
}
private void FixedUpdate()
{
if (_rightMouseDown)
{
Debug.Log("Rotate");
//Set the target rotation based on the mouse delta position and our rotation speed
_rotationTarget *= Quaternion.AngleAxis(_mouseDelta.x * Time.deltaTime * RotationSpeed, Vector3.back);
//Slerp the camera rig's rotation based on the new target
transform.rotation = Quaternion.Slerp(transform.rotation, _rotationTarget, Time.deltaTime * InternalRotationSpeed);
}
}