// 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); } }
void Start() { controller = GetComponent <ActorMove>(); if (controller != null) { controller.SetActorState(seekerState); controller.SetGroup(group); } }
// Use this for initialization void Start() { Pos = new Vector2(transform.position.x - PathFind.instance.m_map.mapStartPos.x, transform.position.z - PathFind.instance.m_map.mapStartPos.z); neighbourRadiusSquaredMoving = neighbourRadiusMoving * neighbourRadiusMoving; neighbourRadiusSquaredIdle = neighbourRadiusIdle * neighbourRadiusIdle; SetNeighbourRadius(seekerState); neighbours = new Seeker[SeekerMovementManager.maxNeighbourCount]; SeekerMovementManager.AddSeeker(this); controller = GetComponent <ActorMove>(); if (controller != null) { controller.SetActorState(seekerState); controller.SetGroup(group); } }