//pathfinding public void MoveEnemy() { if (!skipMove) { Stack <Vector2> moveStack = PathFinding.Calculate(transform.position, target.position); if (moveStack.Count != 0) { RaycastHit2D hit; if (stepsPerTurn > 1) { for (int i = 0; i < stepsPerTurn - 1; i++) { if (moveStack.Count > 1) { moveStack.Pop(); //maybe let the zombie move every pop? } } } Vector2 nextMove = moveStack.Pop(); Debug.Log("Next"); //Debug.Log(nextMove); int xDir = (int)(nextMove.x - transform.position.x); int yDir = (int)(nextMove.y - transform.position.y); lastDirectionRight = (xDir > 0 ? true : false); spriteRenderer.flipX = lastDirectionRight; //Tries to move to location, Moves if it can move if (!Move(xDir, yDir, out hit)) { //if colides with something determine if its wall or player Component hitComponent = hit.transform.GetComponent <Wall>(); if (hitComponent == null) { hitComponent = hit.transform.GetComponent <Player>(); } //If determined as wall or Player if (hitComponent != null) { OnCantMove(hitComponent); } } //for next turn skipMove = true; } } else { skipMove = false; } }
//pathfinding public void MoveEnemy() { if (!skipMove) { Stack <Vector2> moveStack = PathFinding.Calculate(transform.position, target.position); if (moveStack.Count != 0) { RaycastHit2D hit; if (moveStack.Count <= range) { if (target.gameObject.tag == "Player") { OnCantMove(target.transform.GetComponent <Player>()); //attack when in range } else if (target.gameObject.tag == "Raider") { OnCantMove(target.transform.GetComponent <Raider>()); } else if (target.gameObject.tag == "Enemy") { OnCantMove(target.transform.GetComponent <Enemy>()); } } Vector2 nextMove = moveStack.Pop(); Debug.Log("Next"); //Debug.Log(nextMove); int xDir = (int)(nextMove.x - transform.position.x); int yDir = (int)(nextMove.y - transform.position.y); raiderLastDirectionRight = (xDir > 0 ? true : false); raiderRenderer.flipX = raiderLastDirectionRight; //Tries to move to location, Moves if it can move if (!Move(xDir, yDir, out hit)) { //if colides with something determine if its wall or player Component hitComponent = hit.transform.GetComponent <Wall>(); if (hitComponent == null) { hitComponent = hit.transform.GetComponent <Player>(); } //If determined as wall or Player if (hitComponent != null) { OnCantMove(hitComponent); } } //for next turn skipMove = true; } } else { skipMove = false; } }