unity3d实现3D物体上的点击事件

首先要在摄像机中添加组件Physics Raycaster

void Update () {
    if(Input.GetMouseButtonUp(0)){
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit rayhit;
        if (Physics.Raycast(ray, out rayhit))
        {
            Debug.Log(rayhit.collider.gameObject.name);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/PixelBoy/article/details/85003875