void Update () {
if (Input.GetMouseButtonDown (0)) {
ClickCube();
}
}
/*
点击物体
*/
private void ClickCube(){
RaycastHit raycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out raycastHit)) {
Debug.Log(raycastHit.transform.name);
//raycastHit.point 为点击的物体的具体位置
}
}
Unity 实现点击物体
最新推荐文章于 2024-09-06 22:34:17 发布