c# - C# Unity 2D 代码中的大括号预期错误
问题描述
我已经尝试了以下 C# 代码来统一,我在} expected [Assembly-CSharp]csharp(CS1513)
我标记的大括号上遇到了一个错误,在最后一个大括号上我有一个Type or namespace definition, or end-of-file expected [Assembly-CSharp]csharp(CS1022)
错误,当我删除它时它会留下,但是它应该结束 Monobehavior 主体。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{ // error here
public static float ScrollWheel { get { return Input.mouseScrollDelta.y / 10; } }
}
} // and also here
解决方案
具体来说,您在方法中包含了一个属性。但是,请注意,您可以在其他成员中包含本地函数。
如果您的意图是简单地获得该值,您可以像这样构造您的代码:
public class NewBehaviourScript : MonoBehaviour
{
public static float ScrollWheel => Input.mouseScrollDelta.y / 10;
// Start is called before the first frame update
void Start ( )
{
}
// Update is called once per frame
void Update ( )
{
}
}
我为 ScrollWheel 值使用了Lambda表达式。
推荐阅读
- awk - 如何用该字母替换多次出现的字母?
- vb.net - 如何在列表框中堆叠 mp3 文件
- java - 多个登录 URL Spring Security
- c - 输出窗口中的 UTF-8 字符编辑不正确
- python - 如何将切片对象的负索引解析为 argparse.ArgumentParser
- swift - Go vs Swift 中的 UTF8 字符串长度和索引
- tfs - 如何在 TFS 中查看 Epic
- ios - SearchResultsController 与 UINavigationItem 一起使用时会遮挡屏幕
- mysql - 创建引用元值的 sql 查询
- python - python - 使用一些哈希技术比较签名时使用opencv和python时numpy出错