/// <summary> /// Walks to position. /// </summary> /// <param name="position">Position.</param> public void WalkToPosition(Vector3 position) { this.CancelWalk(); if (SceneManager.instance.gameMode == Common.GameMode.NORMAL) { //on user city walls are not considered this.WalkThePath(GroundManager.instance.GetPath(this.transform.position, position, false)); } else if (SceneManager.instance.gameMode == Common.GameMode.ATTACK) { GroundManager.Path pathWithoutWalls = GroundManager.instance.GetPath(this.transform.position, position, false); GroundManager.Path pathWithWalls = GroundManager.instance.GetPath(this.transform.position, position, true); // Debug.Log (pathWithWalls.GetDistanceAlongPath ()); // Debug.Log (pathWithoutWalls.GetDistanceAlongPath ()); float difference = pathWithWalls.GetDistanceAlongPath() - pathWithoutWalls.GetDistanceAlongPath(); if (difference > 0 && difference <= 4) { this.WalkThePath(pathWithWalls); } else { this.WalkThePath(pathWithoutWalls); } } }
/// <summary> /// Walks the path. /// </summary> /// <param name="path">Path.</param> public void WalkThePath(GroundManager.Path path) { if (path.nodes == null || path.nodes.Length == 0) { //no path found this.FinishWalk(); return; } this._baseItem.SetState(Common.State.WALK); this._path = path; this._currentNodeIndex = 0; if (path != null && path.nodes != null && path.nodes.Length > 0) { this.MoveToPosition(this._path.nodes[0]); } }