可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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; } }