Showing menu make the cursor disappear

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

The cursor disappears when making a single click, like so:

How to reproduce:

  • get the Game Jam Menu template: https://www.assetstore.unity3d.com/en/#!/content/40465
  • Add another scene with an FPS controller imported from the standard assets.
  • Tick the "change scenes" in the UI -> start options component.

  • Press escape and touch the slider, any single click will make the cursor disappear.

It looks like this: https://imgur.com/a/hefmP

If I tick off the mouse look -> lock cursor in the FPS controller then this doesn't happen, but I also see the cursor in my FPS game.

I tried to add Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; and the opposite when pausing and unpausing but it doesn't help. Probably because the MouseLook.cs is also updating them in:

I'd rather not couple the FPSController and the pause menu and they're also in different scenes.

So how else can I unlock the cursor when entering the pause menu? Is there an event pattern that can be used here?

It also darkens the scene, but that's for another question.

回答1:

It's been modified by the MouseLook script which is used in the FirstPersonController script. One solution is to modify the MouseLook script but a simple Asset update would kill that modification.

A proper solution to this problem is to disable the FirstPersonController script when you open up any menu and then enable it back when you close that menu. Also, when you disable it, manually set Cursor.lockState to None and set the cursor to visible.

Below is a simple function that will handle that. Each of your menu open and close button should be linked to the function below. When you call it, pass false to it with the open button and true to it with the close button:

void enableFPS(bool enable) {     GameObject fpsObj = GameObject.Find("FPSController");     FirstPersonController fpsScript = fpsObj.GetComponent();      if (enable)     {         //Enable FPS script         fpsScript.enabled = true;     }     else     {         //Disable FPS script         fpsScript.enabled = false;         //Unlock Mouse and make it visible         Cursor.lockState = CursorLockMode.None;         Cursor.visible = true;     } } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!