Getting the mouse position using the new Input System

If you want to use Unity’s new Input System to get the mouse’s position you can use Mouse.current.position.ReadValue() instead of using Input.mousePosition

Take note that this is a Vector2

        private void AdjustPlayerFacingDirection()
            if (!_hasCamera) return;
            Vector3 mousePosition = Mouse.current.position.ReadValue();
            var playerScreenPosition = _camera.WorldToScreenPoint(transform.position);

            _isFacingLeft = mousePosition.x < playerScreenPosition.x;
            _spriteRenderer.flipX = _isFacingLeft;

This took some digging in the docs for the new Input System.

1 Like

Privacy & Terms