IEnumerator ChaseSound(Vector2 destination, Floor targetFloor) { // Debug.Log("Begin"); bool isOnStair = _isOnStair; List<Vector2> path; if (!isOnStair) path = new FloorSearcher(GetPos(), destination, currentFloor, targetFloor).GetPath(); else path = new FloorSearcher(GetPos(), destination, null, targetFloor, currentStair, null).GetPath(); Queue<Vector2> pathQueue = new Queue<Vector2>(); if (path == null) { // Debug.Log("Null path"); yield break; } if (path.Count == 0) { // Debug.Log("zero path"); yield break; } for (int i=0; i<path.Count; i++) { pathQueue.Enqueue(path[i]); } while(pathQueue.Count > 0) { Vector2 nextDestine = pathQueue.Dequeue(); if (isDebugMode) { Destroy(cube); cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = nextDestine; } Vector2 pastDestine = Vector2.zero; if (!isOnStair) { float direction = Mathf.Sign(nextDestine.x - GetPos().x); Move(direction); while(Mathf.Abs(nextDestine.x - GetPos().x) > 0.05f) { Move(direction); yield return null; } BeStay(); isOnStair = true; // Debug.Log("Stair!"); } else { float direction = Mathf.Sign(nextDestine.x - GetPos().x); if (transform.position.y < nextDestine.y) { nextDestine += Vector2.right * direction; body.velocity = Vector2.up * 5; yield return new WaitForSeconds(0.5f); } else { nextDestine += Vector2.right * 2f * direction; DownFloor(); } Move(direction); while(Mathf.Abs(nextDestine.x - GetPos().x) > 0.5f) { Move(direction); yield return null; } BeStay(); isOnStair = false; } pastDestine = nextDestine; } }
IEnumerator ChaseSound(Vector2 destination, Floor targetFloor) { // Debug.Log("Begin"); bool isOnStair = _isOnStair; List <Vector2> path; if (!isOnStair) { path = new FloorSearcher(GetPos(), destination, currentFloor, targetFloor).GetPath(); } else { path = new FloorSearcher(GetPos(), destination, null, targetFloor, currentStair, null).GetPath(); } Queue <Vector2> pathQueue = new Queue <Vector2>(); if (path == null) { // Debug.Log("Null path"); yield break; } if (path.Count == 0) { // Debug.Log("zero path"); yield break; } for (int i = 0; i < path.Count; i++) { pathQueue.Enqueue(path[i]); } while (pathQueue.Count > 0) { Vector2 nextDestine = pathQueue.Dequeue(); if (isDebugMode) { Destroy(cube); cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = nextDestine; } Vector2 pastDestine = Vector2.zero; if (!isOnStair) { float direction = Mathf.Sign(nextDestine.x - GetPos().x); Move(direction); while (Mathf.Abs(nextDestine.x - GetPos().x) > 0.05f) { Move(direction); yield return(null); } BeStay(); isOnStair = true; // Debug.Log("Stair!"); } else { float direction = Mathf.Sign(nextDestine.x - GetPos().x); if (transform.position.y < nextDestine.y) { nextDestine += Vector2.right * direction; body.velocity = Vector2.up * 5; yield return(new WaitForSeconds(0.5f)); } else { nextDestine += Vector2.right * 2f * direction; DownFloor(); } Move(direction); while (Mathf.Abs(nextDestine.x - GetPos().x) > 0.5f) { Move(direction); yield return(null); } BeStay(); isOnStair = false; } pastDestine = nextDestine; } }