unity3d 一直报错。显示A namespace cannot directly contain members such as fields or methods。

问题遇到的现象和发生背景

想做碰撞消失

表头表头
单元格单元格
单元格单元格
问题相关代码,请勿粘贴截图
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
    {
        private Rigidbody xq;
        // Start is called before the first frame update
        void Start()
        {
            xq = GetComponent<Rigidbody>();
        }

        // Update is called once per frame
        void Update()
        {
            float h = Input.GetAxis("Horizontal");
            float t = Input.GetAxis("Vertical");
            xq.AddForce(new Vector3(-h, 0, -t));
            if (Input.GetKey(KeyCode.Space))
            {
                xq.AddForce(new Vector3(0, 2, 0));
            }
        }
    }
void OnCollisonEnter(Collision cd)
{
    if (cd.collider.tag == "Pickup")
        Destroy(cd.collider.gameObject);
}

运行结果及报错内容

Assets\player.cs(25,6): error CS0116: A namespace cannot directly contain members such as fields or methods

我的解答思路和尝试过的方法
我想要达到的结果

让其正常运行

将第24行的括号放到30行即可;方法要定义到类里面。

img