unity – How can I make a script that I will be able to lock/unlock the mouse movements from any other scripts?


I’m using on the player the components : ThirdPersonUserControl and ThirdPersonCharacter.

And I have started this script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseController
{
   public static void MouseControl(bool MouseLockState)
    {
        if(MouseLockState == true)
        {
            Cursor.visible = false;
            Cursor.lockState = CursorLockMode.Locked;
        }
    }
}

The main goal is to control the mouse movements for example in dialogues to disable the mouse or in cutscenes and then to enable it again.