Physics2D.LinecastNonAlloc 直线投射不分配内存
C# ⇒ static int LinecastNonAlloc(Vector2 start, Vector2 end, RaycastHit2D[] results, int layerMask = DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity);
start:直线在世界空间的开始点。
end :直线在时间空间的结束点。
results:返回与直线相交的物体数组。 返回结果的数量(int)。
layerMask:只在某些层过滤检测碰撞器。
minDepth:只包括Z坐标(深度)大于这个值的对象。
maxDepth:只包括Z坐标(深度)小于这个值的对象。
具体 实例`using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public Transform targetpos;//目标位置//
RaycastHit2D [] ray;
int hitNumber =0;//检测返回与直线相交的物体数量//
// Use this for initialization

本文介绍Unity3D中2D射线检测的使用,通过LinecastNonAlloc函数实现直线投射,无需分配内存。讲解了函数参数含义,如起点、终点、结果数组、层过滤和深度限制,并提供了具体的C#代码示例。
最低0.47元/天 解锁文章
2010

被折叠的 条评论
为什么被折叠?



