usingUnityEngine; usingSystem.Collections.Generic; usingPathfinding; publicclassTest:MonoBehaviour { privateSeekerseeker; privateList<Vector3> vPath; voidAwake() { seeker = GetComponent<Seeker>(); } voidUpdate() { if(Input.GetMouseButtonDown(1)) { Rayray =Camera.main.ScreenPointToRay(Input.mousePosition);//射线,从摄像机到鼠标位置的一条射线 RaycastHitraycastHit;//碰撞体信息 if(Physics.Raycast(ray,outraycastHit, 81f)) { //raycastHit.point碰撞到的点 seeker.StartPath(transform.position,raycastHit.point , OnPathComplete); } } if(vPath!=null&& vPath.Count > 1) { for(inti = 0; i < vPath.Count; i++) { inti2 = i + 1; if(i2 <= vPath.Count - 1) { Debug.DrawLine(vPath[i],vPath[i2],Color.green); } } } } voidOnPathComplete(Pathp) { if(!p.error) { ABPathabPath = pasABPath; 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); } } } |