C# Unity 2D 代码中的花括号预期错误 [英] Curly Brace Expected Error in C# Unity 2D Code
问题描述
为了统一,我尝试了以下 C# 代码,并且在我标记的花括号上得到了 } 预期的 [Assembly-CSharp]csharp(CS1513)
错误,然后最后一个花括号我有一个 Type 或命名空间定义,或者文件结尾预期的 [Assembly-CSharp]csharp(CS1022)
错误,当我删除它时会留下,但它应该结束 Monobehavior 主体.
I've tried the following C# code for unity, and I've gotten a } expected [Assembly-CSharp]csharp(CS1513)
error on the curly brace I've marked, and on the last curly brace I've got a Type or namespace definition, or end-of-file expected [Assembly-CSharp]csharp(CS1022)
error on it, that leaves when I delete it, but it should end the Monobehavior body.
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
推荐答案
在方法中创建属性导致了这个问题.如果您的目标是在每一帧中获取鼠标滚动数据(这是另一个优化问题),您可以这样做:
Creating a property inside a method caused this problem. If your goal was to get the mouse scroll data in every frame (which is an optimization issue for another time), you may do it like so:
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()
{
//call the method here
ScrollWheel();
}
public static float ScrollWheel ();
{
return Input.mouseScrollDelta.y / 10;
}
}
我创建了一个方法而不是像上面那样的属性,但这应该类似.
I created a method instead of a property like above, but this should work similarly.
这篇关于C# Unity 2D 代码中的花括号预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!