public void AttemptMove() { if (turnSpeed != turnSpeedCounter) { turnSpeedCounter++; return; } turnSpeedCounter = 1; CalculateObstacles(); path = ABPath.Construct(movingToPoint.position, target.position, null); path.traversalProvider = traversalProvider; AstarPath.StartPath(path); path.BlockUntilCalculated(); if (!path.error) { if (path.vectorPath.Count > 2) { movingToPoint.position = path.vectorPath[1]; blocker.BlockAt(path.vectorPath[1]); path.vectorPath.RemoveAt(0); } else if (path.vectorPath.Count <= 2 && target == FindObjectOfType <PlayerMovePoint>().transform) { //ATTACK PLAYER Health playerHealth = FindObjectOfType <PlayerMovement>().GetComponent <Health>(); playerHealth.DecreaseHealth(GetComponent <DamageDealer>().GetDamage()); } } }
// Update is called once per frame protected void Update() { //base.Update(); path = ABPath.Construct(this.transform.position, this.GetComponent <EnemyAI>().target.position, null); path.traversalProvider = traversalProvider; AstarPath.StartPath(path); path.BlockUntilCalculated(); path.Claim(this); if (path.error == true) { Debug.Log("No Path Was Found."); } else { Debug.Log("A Path Was Found With: " + path.vectorPath.Count + " Nodes"); for (int i = 0; i < path.vectorPath.Count - 1; i++) { Debug.DrawLine(path.vectorPath[i], path.vectorPath[i + 1], Color.red); } this.GetComponent <Seeker>().StartPath(path.startPoint, path.endPoint, OnPathCompleteCallback); } }