FPS射击对象是从,主相机中心发射出的子弹,并不是枪口发射的子弹
public Transform shotSton;//相机
void Shout()
{
RaycastHit hit;//击中的对象
if (Physics.Raycast(shotSton.transform.position,shotSton.forward,out hit))//括号中(主相机、方向、out 返回的物体、限制的距离)ps:这里我没写限制的距离
{
this.Post(hit.point);//传的是坐标
}
}
void Post(Vector3 vet)//生成预制体
{
GameObject gam = Instantiate<GameObject>(Resources.Load<GameObject>("Cube"));
gam.transform.position = vet;
}