private void Update() { Debug.Log("target = " + target); Debug.Log("Player.position = " + player.position); Debug.Log(StaticNodeLibrary.FindClosestWalkablePosition(player)); MoveTowardTarget(); }
protected void AttackClosestObject() { //If Player cannot be reached, then the zombie searches for the closest object and goes to attack it by making the object the target of the seeker. int layerMask = 1 << 9; layerMask = ~layerMask; Vector2 directionPlayer = (player.position - transform.position); RaycastHit2D hit = Physics2D.Raycast(transform.position, directionPlayer, Vector3.Distance(transform.position, player.transform.position), layerMask); Debug.DrawRay(transform.position, directionPlayer); Debug.Log("Tag " + hit.transform.tag); if (hit.transform.tag == "Base") { //Includes check the player isn't actually reachable in a straight line, covers for problem with A* and possible movement of the player target = StaticNodeLibrary.FindClosestWalkablePosition(hit.transform); Debug.Log(StaticNodeLibrary.FindClosestWalkablePosition(hit.transform)); Debug.Log(hit.transform.tag); seeker.StartPath(transform.position, target, OnPathComplete); } else if (hit.transform.tag == "Player") { target = player.position; status = ZombieState.detected; seeker.StartPath(transform.position, target, OnPathComplete); } }