using
UnityEngine;
using
System.Collections.Generic;
using
Pathfinding;
public
class
Test
:
MonoBehaviour
{
private
Seeker
seeker;
private
List
<
Vector3
> vPath;
void
Awake()
{
seeker = GetComponent<
Seeker
>();
}
void
Update()
{
if
(
Input
.GetMouseButtonDown(1))
{
Ray
ray =
Camera
.main.ScreenPointToRay(
Input
.mousePosition);
//
射线
,
从摄像机到鼠标位置的一条射线
RaycastHit
raycastHit;
//
碰撞体信息
if
(
Physics
.Raycast(ray,
out
raycastHit, 81f))
{
//raycastHit.point
碰撞到的点
seeker.StartPath(transform.position,raycastHit.point , OnPathComplete);
}
}
if
(vPath!=
null
&& vPath.Count > 1)
{
for
(
int
i = 0; i < vPath.Count; i++)
{
int
i2 = i + 1;
if
(i2 <= vPath.Count - 1)
{
Debug
.DrawLine(vPath[i],vPath[i2],
Color
.green);
}
}
}
}
void
OnPathComplete(
Path
p)
{
if
(!p.error)
{
ABPath
abPath = p
as
ABPath
;
if
(abPath ==
null
)
{
Debug
.Log(
"This function only handles ABPaths, do not use special path types"
);
}
//Claim the new path
p.Claim(
this
);
// Path couldn't be calculated of some reason.
// More info in p.errorLog (debug string)
if
(p.error)
{
p.Release(
this
);
return
;
}
vPath = abPath.vectorPath;
}
else
{
Debug
.Log(
"Yay, we got a path back. Did it have an error? "
+ p.error);
}
}
}
|