unity Debug.DrawLine画线

unity Debug.DrawLine画线


C# => public static void DrawLine(Vector3 start, Vector3 end, Color color = Color.white, float duration = 0.0f, bool depthTest = true);
在指定的起点与终点之间画条线。

参数 解释
start 世界空间中线条应该开始的点
end 世界空间中线条应该结束的点
color 线条颜色
duration 线条可持续显示时间(以秒为单位)
depthTest 线是否应该被靠近相机的物体遮挡?
void Update () {
        //返回一条射线从摄像机通过一个屏幕点
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo = new RaycastHit();
        //(射线的起点和方向,hitonfo将包含碰到碰撞器的更多信息,射线的长度)有碰撞时,返回真
        if (Physics.Raycast(ray, out hitInfo, 100)){
            //显示检测到的碰撞物体的世界坐标
            print(hitInfo.point);
            Debug.DrawLine(transform.position, hitInfo.point,Color.red);
        }
	}

注意:运行时,该线条只在编辑窗口的场景中显示。在可持续的时间内(以秒为单位)该线将在第一次显示后可见。duration值为0表示该线仅显示一帧可见。 该画线方法仅供调试。平台发布后不显示。
unity Debug.DrawLine画线_第1张图片

你可能感兴趣的:(unity学习,unity入门)