Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 退出暂停菜单时我的光标保持可见,即使我已调用光标。退出菜单时可见功能_C#_Unity3d_Cursor_Visible - Fatal编程技术网

C# 退出暂停菜单时我的光标保持可见,即使我已调用光标。退出菜单时可见功能

C# 退出暂停菜单时我的光标保持可见,即使我已调用光标。退出菜单时可见功能,c#,unity3d,cursor,visible,C#,Unity3d,Cursor,Visible,我正在制作游戏中的暂停菜单。我的游戏将光标锁定在适当的位置,然后隐藏光标,这样就不会分散用户的注意力。在我暂停游戏之前,它一直按预期工作。光标变为可见(在“暂停”功能中将光标.visible设置为true),并且“暂停”菜单正常工作。但是,当我再次按escape退出菜单时,光标在屏幕上的位置仍然可见 我怎样才能解决这个问题 谢谢 这是我的密码: using UnityEngine; public class PlayerCameraRotation : MonoBehaviour {

我正在制作游戏中的暂停菜单。我的游戏将光标锁定在适当的位置,然后隐藏光标,这样就不会分散用户的注意力。在我暂停游戏之前,它一直按预期工作。光标变为可见(在“暂停”功能中将光标.visible设置为true),并且“暂停”菜单正常工作。但是,当我再次按escape退出菜单时,光标在屏幕上的位置仍然可见

我怎样才能解决这个问题

谢谢

这是我的密码:

using UnityEngine;

public class PlayerCameraRotation : MonoBehaviour
{
    Vector2 mouseDirection;      //Initialises Mouse Direction.                                                                    
    Vector2 smoothValue;         // Initialises The Smoothing Value.                                                                           
    private float sensitivity = 1.0F;     // Sets The Sensitivity To 1.                                                             
    private float smoothing = 2.0F;           // Sets Smoothing To 2.
    private GameObject cameraDirection;       // Initialises Camera Direction.
    Vector2 mouseD;
    private bool gamePause = false;

void Start()                                                                                      // Calls Once As Soon As The Program Is Started.
{
    cameraDirection = transform.parent.gameObject;                                                 // Rotates The Camera To Face The Same Direction As The Player.
}


void LateUpdate()                                                                                 // Updates Every Frame After All Other Updates Have Been Completed.
{
    if(gamePause == false)
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }
    mouseD = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
    mouseD = Vector2.Scale(mouseD, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
    smoothValue.x = Mathf.Lerp(smoothValue.x, mouseD.x, 1f / smoothing);
    smoothValue.y = Mathf.Lerp(smoothValue.y, mouseD.y, 1f / smoothing);
    mouseDirection += smoothValue;
    mouseDirection.y = Mathf.Clamp(mouseDirection.y, -90f, 90f);

    transform.localRotation = Quaternion.AngleAxis(-mouseDirection.y, Vector3.right);
    cameraDirection.transform.localRotation = Quaternion.AngleAxis(mouseDirection.x, cameraDirection.transform.up);

    if (Input.GetKeyDown("escape"))
    {
        if(gamePause == true)
        {
            ResumeGame();
            gamePause = false;

        }
        else
        {
            PauseGame();
            gamePause = true;
        }
    }
}

private void ResumeGame()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    smoothing = 2F;
}

private void PauseGame()
{
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    smoothing = 0F;
}
}

这里的问题似乎是,当您在Unity编辑器中运行代码时,光标不会消失,但当构建并运行相同的代码时,光标会按预期消失。通过生成项目并运行.exe文件解决了此问题。

第一步是调试它。您能否检查这是一个仅限于编辑器的问题,还是在实际生成中仍然存在此问题?因为Unity的焦点处理可能会干扰Esc快捷方式。@PhilippLenssen感谢您的评论。当程序生成时,问题就解决了。您是正确的,这一定是Unity编辑器的问题,因为在构建程序时,光标会按照预期的方式不可见。谢谢你的建议!