射线检测
Posted 扎北强子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了射线检测相关的知识,希望对你有一定的参考价值。
using UnityEngine; using System.Collections; public class RayCastDemo : MonoBehaviour { //射线碰撞检测器 RaycastHit hit; void Update() { //通过鼠标屏幕坐标,生成一条射线对象 Ray r = Camera.main.ScreenPointToRay (Input.mousePosition); //发射射线,并检测 if (Physics.Raycast (r, out hit)) { //获取射线起点 Vector3 begin = Camera.main.transform.position; //获取射线终点 Vector3 end = hit.point; //根据起点终点划线 Debug.DrawLine (begin, end,Color.red); } } }
以上是关于射线检测的主要内容,如果未能解决你的问题,请参考以下文章