Forum rules - please read before posting.

Cursor locked in middle of screen when switching First Person to Point And Click via script

edited April 17 in Technical Q&A

Hi Chris,

I am using the following C# script that is triggered when the player clicks on a hotspot. I'm switching the movement method from First Person to Point and Click. Everything works fine, however, when the coroutine finishes running, the cursor stays locked in the middle of the screen and I am unable to move it with my mouse. I've tried everything.

    public void StartKeyPadInteraction()
    {
        StartCoroutine(FocusOnKeypadReader());

   }

   private IEnumerator FocusOnKeypadReader()
   {

       // Place the game in a cutscene
       KickStarter.stateHandler.EnforceCutsceneMode = true;
       yield return new WaitForSeconds(0.20f);

       KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
       KickStarter.stateHandler.SetMovementSystem(false);


       KickStarter.mainCamera.SetGameCamera(KeypadReaderCamera, 1.0f, MoveMethod.EaseOut);

       while (KickStarter.mainCamera.IsInTransition())
       {
           yield return new WaitForFixedUpdate();
       }
       //yield return new WaitForSeconds(2f);
       if (KeyPadReaderHotSpot != null)
       {
           KeyPadReaderHotSpot.TurnOff();
       }
       else
       {
           Debug.LogError("Hotspot not found");
       }


       // 3. Lock "pause"
       Menu pauseMenu = PlayerMenus.GetMenuWithName("Pause");
       if (pauseMenu != null)
       {
           pauseMenu.isLocked = true;
       }
       else
       {
           Debug.LogError("Menu not found: pause");
       }
       yield return new WaitForSeconds(0.10f);


       KickStarter.cursorManager.pointerIcon = AC.KickStarter.cursorManager.GetCursorIconFromID(3);

       keypadReaderLockController.enabled = true;
       KickStarter.stateHandler.EnforceCutsceneMode = false;

   }

Comments

  • Ok, I found the solution, by adding the following in the Coroutine. I hope this is the right approach?

     if (AC.KickStarter.playerInput.IsCursorLocked())
     {
         Debug.Log("The Cursor is locked!");
         KickStarter.playerInput.SetInGameCursorState(false);
     }
    
  • Yes, SetInGameCursorState is the way to lock/unlock the cursor through scripting.

  • Thanks Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.