在3D场景中基本的操作就是鼠标对物体的点击和悬浮并获得该物体
1.从摄像机发出射线,发射目标为鼠标点击的位置,判断是否碰撞到物体
2.针对每种物体或每个物体设置相应的内容
场景设置如下:
下面的程序是处理点击获取物体的基本架构
public class clickedinfo: MonoBehaviour
{
// Update is called once per frame
void Update()
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
bool cube = false;
bool sphere = false;
bool cylinder = false;
//鼠标悬浮的操作(鼠标点击场景任何地方后)
if(hit.collider.gameObject.name=="Cube")
{
Debug.Log("Mouse on the Cube");
cube = true;
}
else if (hit.collider.gameObject.name &