简体   繁体   English

c#无法将类型“布尔”隐式转换为“ UnityEngine.CursorLockMode”

[英]c# Cannot implicitly convert type 'bool' to 'UnityEngine.CursorLockMode'

I have tried to make a menu system in unity using c# 我试图使用c#统一制作菜单系统

the script I use to hide and show keeps coming back with this error: 我用来隐藏和显示的脚本不断出现此错误:

Cannot implicitly convert type 'bool' to 'UnityEngine.CursorLockMode' 无法将类型'bool'隐式转换为'UnityEngine.CursorLockMode'

here is the code 这是代码

using UnityEngine;
using System.Collections;

public class Pause : MonoBehaviour {

    public GameObject Canvas;
    public GameObject Camera;
    bool Paused = false;

    void Start(){
        Canvas.gameObject.SetActive (false);
    }

    void Update () {
        if (Input.GetKey ("escape")) {
            if(Paused == true){
                Time.timeScale = 1.0f;
                Canvas.gameObject.SetActive (false);
                Cursor.visible = false;
                Cursor.lockState = true;
                Paused = false;
            } else {
                Time.timeScale = 0.0f;
                Canvas.gameObject.SetActive (true);
                Cursor.visible = true;
                Cursor.lockState = false;
                Paused = true;
            }
        }
    }
    public void Resume(){
        Time.timeScale = 1.0f;
        Canvas.gameObject.SetActive (false);
        Cursor.visible = false;
        Cursor.lockState = true;
    }
}

Cursor.lockState isn't a boolean, is of type CursorLockMode . Cursor.lockState不是布尔值,类型为CursorLockMode

You need to set it to CursorLockMode.Locked or possibly CursorLockMode.Confined (depending on what you want to do) and CursorLockMode.None 您需要将其设置为CursorLockMode.Locked或可能CursorLockMode.Confined (取决于你想要做什么)和CursorLockMode.None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何将布尔值转换为Unityengine.Cursorlockmode - how i convert a bool to a Unityengine.Cursorlockmode 无法将类型'bool'隐式转换为'UnityEngine.RaycastHit' - Cannot implicitly convert type `bool' to `UnityEngine.RaycastHit' 无法将布尔类型隐式转换为System.DateTime(C#) - Cannot implicitly convert type bool to System.DateTime (C#) C#无法将类型'string'隐式转换为'bool'错误 - C# Cannot implicitly convert type 'string' to 'bool' error 错误 CS0029:无法将类型“bool”隐式转换为“(bool valorA, bool valorB)”c# - error CS0029: Cannot implicitly convert type 'bool' to '(bool valorA, bool valorB)' c# 无法隐式转换类型'UnityEngine.Vector2?'到'UnityEngine.Vector2' - Cannot implicitly convert type 'UnityEngine.Vector2?' to 'UnityEngine.Vector2' 无法将类型“UnityEngine.AudioClip”隐式转换为“UnityEngine.AudioSource” - Cannot implicitly convert type 'UnityEngine.AudioClip' to 'UnityEngine.AudioSource' 不能隐式转换类型bool? - Cannot implicitly convert type bool? CS0266 C# 无法将类型“UnityEngine.Object”隐式转换为“”。 存在显式转换(您是否缺少演员表?) - CS0266 C# Cannot implicitly convert type 'UnityEngine.Object' to ''. An explicit conversion exists (are you missing a cast?) 无法隐式转换类型“布尔”? “布尔” - Cannot implicitly convert type 'bool?' to 'bool'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM