想做碰撞消失
表头 | 表头 |
---|---|
单元格 | 单元格 |
单元格 | 单元格 |
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行即可;方法要定义到类里面。