赞
踩
在Unity中,可以从一个点向一个方向发射虚拟球体,指定球体半径、投射长度。
在发射轨迹中与其他物体发生碰撞时,它将终止,并返回碰撞信息。
接口
Physics.SphereCastAll
例
- var screenPos = Input.mousePosition;
- // 触碰点的世界坐标,距离摄像机5米的距离
- var worldPos = Camera.main.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 5));
- // 摄像机的世界坐标
- var camPos = Camera.main.transform.position;
- // 球体半径
- var radius = 0.25f;
- // 投射长度
- var lineLen = 100;
- RaycastHit[] hits = Physics.SphereCastAll(camPos, radius, worldPos - camPos, lineLen);
- if(hits.Length > 0)
- {
- if(hits[0].collider.gameObject.tag == "dddd") //用layer也可以//
- {
-
- }
- }

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