【问题标题】:How do I fix: Cannot convert lambda expression to type 'bool' because it is not a delegate type [closed]我该如何解决:无法将 lambda 表达式转换为“bool”类型,因为它不是委托类型 [关闭]
【发布时间】:2020-09-30 00:57:12
【问题描述】:

我一直在将保存的 HighScore 系统添加到我的游戏中,但我收到了这个错误:

无法将 lambda 表达式转换为类型 'bool',因为它不是委托类型

这是我的脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HighScoreDisplay : MonoBehaviour
{
    public Text Display;
    public static int Score;
    private int HighScore;
    private int LateScore;

    void Start()
    {
        HighScore = PlayerPrefs.GetInt("HighScore", 0);
    }

    // Update is called once per frame
    void Update()
    {
        Display.text = (Score.ToString());

        // This is the error
        if (Score => HighScore)
        {
            HighScore = Score;
            Score = 0;
        }
        // ^This is the error^

        if (HighScore == LateScore)
        {

        }
        else
        {
        PlayerPrefs.SetInt("HighScore", HighScore);
        }
    }

    void LateUpdate()
    {
        LateScore = HighScore;
    }
}

请帮忙

谢谢 布伦

【问题讨论】:

    标签: c# lambda delegates


    【解决方案1】:

    你需要>=,而不是=>(颠倒顺序) 您只能使用 >= 进行比较,因为 => 用于 lambda 表达式

    【讨论】:

    • 我不知道它这么小。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多