void move(float dt) { float moveDist = dt * m_speed; Vector2 vCurr = new Vector2(transform.position.x, transform.position.z); Vector2 vDest = new Vector2(pathlist[0].x, pathlist[0].z); Vector2 v = vDest - vCurr; Vector2 vDir = v.normalized; if (moveDist >= m_distace) { ///移动距离大于剩余路程 transform.position = pathlist[pathlist.Count - 1]; pathlist.Clear(); } else { ///移动距离小于剩余路程 Vector2 pos; ///移动距离小于当前位置至下一个路点的路程 if (moveDist <= v.magnitude) { pos = vCurr + moveDist * vDir; } else { ///移动距离大于当前位置至下一个路点的路程 vCurr = vDest; moveDist -= v.magnitude; pathlist.RemoveAt(0); if (pathlist.Count > 0) { pos = moveToNext(vDest, moveDist); } else { pos = vCurr; } } float h = 0; h = NavTools.GetHeight(pos.x, pos.y); transform.position = new Vector3(pos.x, h, pos.y); } }
void OnEnable() { navTools = target as NavTools; }