C# &引用;类型或命名空间定义,应为文件结尾;错误

C# &引用;类型或命名空间定义,应为文件结尾;错误,c#,visual-studio,unity3d,C#,Visual Studio,Unity3d,我在一个Unity项目中工作,我得到了标题错误,我不知道我是怎么得到这个错误的,但是我自己试图找出这个错误是很痛苦的。我试图重写产生此错误消息的代码区域,但没有成功 public class PlayerController : MonoBehaviour { public Rigidbody2D theRB; public float movespeed = 5f; private Vector2 moveInput; private Vector2 mou

我在一个Unity项目中工作,我得到了标题错误,我不知道我是怎么得到这个错误的,但是我自己试图找出这个错误是很痛苦的。我试图重写产生此错误消息的代码区域,但没有成功

public class PlayerController : MonoBehaviour
{
    public Rigidbody2D theRB;

    public float movespeed = 5f;

    private Vector2 moveInput;
    private Vector2 mouseInput;

    public float mouseSensitivity = 1f;

    public Camera viewCam;

    public GameObject bulletImpact;

    public int currentAmmo;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        //Player movement
        moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        Vector3 moveHorizontal = transform.up * -moveInput.x;

        Vector3 moveVertical = transform.right * moveInput.y;
        theRB.velocity = (moveHorizontal + moveVertical) * movespeed;
        //player view control
        mouseInput = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * mouseSensitivity;

        transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z - mouseInput.x);
        viewCam.transform.localRotation = Quaternion.Euler(viewCam.transform.localRotation.eulerAngles + new Vector3(0f, mouseInput.y, 0f));

        //Shooting Code
        if(Input.GetMouseButton(0))
        {
            if (currentAmmo > 0)
            {
                Ray ray = viewCam.ViewportPointToRay(new Vector3(.5f, .5f, 0f));
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    //Debug.Log("I'm looking at " + hit.transform.name);
                    Instantiate(bulletImpact, hit.point, transform.rotation);
                }
                else
                {
                    Debug.Log("Im looking at nothing");
                }
            }
            currentAmmo --;
            }
        }
    }
}


显示红色错误曲线的是结束括号。

结束括号太多。请尝试在开始之前移除线上的卷曲括号 当前弹药--


编辑:根据下面的评论调整答案

你有一个额外的结束括号。我会说它需要是之前的括号,在按下if按钮后的括号,我不认为他想减去弹药,即使他没有足够的弹药。这是我在寻找的答案