1,创建一根射线
2,检查射线与其他物体的碰撞,得到碰撞信息
3,通过碰撞信息对碰撞到的物体进行处理

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {
	private Ray ray;
	private RaycastHit hit;
	void Update () {
		// 按鼠标左
		if (Input.GetMouseButton(0))
		{
			// 主相机屏幕点转换为射线
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			//射线碰到了物体
			if (Physics.Raycast(ray,out hit))
			{
				//销毁解除的游戏对象
				GameObject.Destroy(hit.collider.gameObject);
			}
		}
	}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2021-12-26
  • 2021-12-03
  • 2021-05-07
  • 2021-07-15
  • 2022-12-23
相关资源
相似解决方案