赞
踩
一般情况是从摄像机到鼠标点击位置生成射线。
- void Update () {
- if (Input.GetMouseButtonDown(0)) {
- Ray ray = _cam.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit)) {
-
- }
- }
- }
hit是RaycasHit类型
- public struct RaycastHit
- {
-
- public Vector3 point { get; set; }//世界坐标点
-
- public Vector3 normal { get; set; }//法线
-
- public Vector3 barycentricCoordinate { get; set; }//重心坐标
-
- public float distance { get; set; }//距离
-
- public int triangleIndex { get; }//三角形的重心坐标
-
- public Vector2 textureCoord { get; }//UV纹理坐标
-
- public Vector2 textureCoord2 { get; }//次UI纹理坐标
-
- public Vector2 lightmapCoord { get; }//UV光照贴图坐标
-
- public Collider collider { get; }//碰撞器
-
- public Rigidbody rigidbody { get; }//刚体
-
- public Transform transform { get; }//transform属性
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。