游戏工具类

作者:追风剑情 发布于:2022-12-2 18:09 分类:Unity3d

物理辅助类

using System;
using UnityEngine;
/// <summary>
/// 物理辅助类
/// </summary>
public sealed class PhysicsHelper
{
    // Physics.RaycastAll()返回的结果是无序的
    // 将射线返回的碰撞对象按距离排序
    public static void SortRaycastHit(ref RaycastHit[] hits)
    {
        Array.Sort<RaycastHit>(hits,
            (a, b) => {
                if (a.distance < b.distance)
                    return -1;
                else if (a.distance > b.distance)
                    return 1;
                return 0;
            });
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号