Skip to content

Commit

Permalink
Disabled player movement when UI is active.
Browse files Browse the repository at this point in the history
  • Loading branch information
PathogenDavid committed Sep 22, 2024
1 parent 0e9ca84 commit 9b8890b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Assets/HandMadeGame/Code/BirdController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class BirdController : MonoBehaviour
public bool invertVerticalLook;

// movement
private bool suppressMovement = false;
public float moveSpeed = 5f;
public float fastMoveSpeed = 15f;
public float moveSmoothing = 0.8f;
Expand All @@ -30,17 +31,33 @@ public class BirdController : MonoBehaviour

private void Awake()
{
UiController.UiInteractionStart += () => Cursor.lockState = CursorLockMode.None;
UiController.UiInteractionEnd += () => Cursor.lockState = CursorLockMode.Locked;
Cursor.lockState = CursorLockMode.Locked;
UiController.UiInteractionStart += () =>
{
suppressMovement = true;
Cursor.lockState = CursorLockMode.None;
};

UiController.UiInteractionEnd += () =>
{
suppressMovement = false;
Cursor.lockState = CursorLockMode.Locked;
};

Cursor.lockState = CursorLockMode.Locked;
#if !UNITY_EDITOR && UNITY_WEBGL
WebGLInput.stickyCursorLock = false;
#endif
}

private void FixedUpdate()
{
if (suppressMovement)
{
rb.velocity = Vector3.zero;
acceleration = Vector3.zero;
return;
}

// handle movement logic
float horizontalMove = Mathf.Clamp01(Input.GetAxisRaw("Vertical"));
Vector3 targetVelocity = visuals.forward * horizontalMove * (Input.GetKey(KeyCode.LeftShift) ? fastMoveSpeed : moveSpeed);
Expand Down

0 comments on commit 9b8890b

Please sign in to comment.