playMaker

Author Topic: Hide and Show mouse cursor in real time  (Read 4224 times)

6equj5

  • Playmaker Newbie
  • *
  • Posts: 7
Hide and Show mouse cursor in real time
« on: October 31, 2024, 08:24:16 PM »
Hi guys. Help me with this issue.
I have a game with split screen - on the one screen we have FPS controller, on the second screen we have camera above the player like in RTS(i want to combine two gameplay in one scene).
So, in some cases I need to use RTS UI on the second screen, and won’t affect the FPS controller screen at this time.
The idea was show cursor and turn off the FPS controller by pressing TAB button, and reverse back on second press. I did pretty simple fsm with this mechanic in the manager object, but as soon as I show the cursor, I loose control over FPS controller and can’t get it back - its stuck, and nothing happening. I can hide and show cursor but I lost control over controller even I removed all actions relate to freeze and unfreeze this FPS controller.
So, how I can return into FPS controller from RTS camera when I press button?

(I use Unity FPS microgame asset for FPS controller)

digitalannouncer

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Hide and Show mouse cursor in real time
« Reply #1 on: November 06, 2024, 02:14:48 AM »
Cursor and Controller Toggle:
In RTS mode: Cursor.lockState = CursorLockMode.None; Cursor.visible = true; fpsController.SetActive(false);
In FPS mode: Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; fpsController.SetActive(true);
FSM Logic:
Ensure your FSM transitions correctly, disabling RTS input in FPS mode and enabling it only in RTS mode.
public class GameModeManager : MonoBehaviour
{
    public GameObject fpsController;
    public GameObject rtsCamera;
    private bool isInRTSMode = false;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab)) ToggleGameMode();
    }

    void ToggleGameMode()
    {
        isInRTSMode = !isInRTSMode;
        Cursor.lockState = isInRTSMode ? CursorLockMode.None : CursorLockMode.Locked;
        Cursor.visible = isInRTSMode;
        fpsController.SetActive(!isInRTSMode);
        rtsCamera.SetActive(isInRTSMode);
    }
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Hide and Show mouse cursor in real time
« Reply #2 on: November 11, 2024, 04:55:24 AM »
Hi,

Let me know if the post above suits your needs, else I'll explain how to do it in PlayMaker.

Bye,

Jean