title: Unity3D mouse cursor visibility - C#
body: <p>I want to set cursor invisible and locked on the middle of the screen when the game is running, but when in inventory or in menu I want cursor visible and unlocked. I made something like that:</p>
  
  <pre><code>if (tribe == game) {
              Cursor.lockState = CursorLockMode.Locked;
              Cursor.visible = false;
              Time.timeScale = 1;
          } else if (tribe == menu) {
              Cursor.lockState = CursorLockMode.Confined;
              Cursor.visible = true;
              Time.timeScale = 0;
          } else if (tribe == inventory) {
              Cursor.lockState = CursorLockMode.Confined;
              Cursor.visible = true;
              Time.timeScale = 0;
          }
  </code></pre>
  
  <p>Conditions are made properly and work (unless I should call it in every frame), but lock states and visibility is bugged. Sometimes it works, sometimes not (maybe it's caused by the fact I run it in Unity Editor) and it's behave weird.
  Should I call it every frame or I use it wrong or something?</p>