// Update is called once per frame void Update() { if (Linemesh != null) { Graphics.DrawMesh(Linemesh, Vector3.zero, Quaternion.identity, material, 0); } if (listPath == null || listPath.Count == 0 || CurPathNode >= listPath.Count) { seekerState = ActorState.Idle; controller.SetActorState(seekerState); ClearCurve(); } else { //计算与目标点间的距离 des = Vector3.Distance(this.transform.position, listPath[CurPathNode]); movement = (listPath[CurPathNode] - this.transform.position).normalized * speed * Time.deltaTime; //移向目标 //movement controller.MoveAndRotate(movement, seekerState); currentTile = PathFind.instance.m_map.GetMapTile(this.transform.position); //如果移动到当前目标点,就移动向下个目标 if (des < 0.1f && CurPathNode < listPath.Count) { CurPathNode++; } seekerState = ActorState.Moving; controller.MoveAndRotate(movement, seekerState); } }
// Update is called once per frame public void Tick() { switch (seekerState) { case ActorState.Idle: Idle(); break; case ActorState.Moving: Move(); break; } // 判断由没出界 CheckIfMovementLegit(); //movement controller.MoveAndRotate(movement, seekerState); Pos = new Vector2(transform.position.x - PathFind.instance.m_map.mapStartPos.x, transform.position.z - PathFind.instance.m_map.mapStartPos.z); }