有谁知道这里的问题是什么吗?错误是:类型或名称空间定义,或期望的文件结束符


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playershoot : MonoBehaviour
{
public static Action shootInput;
private void Update()
{
if (Input.GetMouseButton(0))
}
{
shootInput?.Invoke();
}
}

我在youtube上看了一个教程(我是c#的新手),并完全按照我所说的去做了,但还是发生了。

你的方法没有正确关闭作用域。你的if语句位于方法右括号的一半位置所以你的语句位于不能合法放置的地方

private void Update()
{
if (Input.GetMouseButton(0))
}
{ //here
shootInput?.Invoke();
} // here

应该如下所示,if语句包含在方法定义中

private void Update()
{
if (Input.GetMouseButton(0))
{
shootInput?.Invoke();
}
}

最新更新