private void GotoWayPoint() { if (_isDead) { return; } string target = GameLogic.Instance.GetRandomRoom(); if (target == string.Empty) { return; } Debug.Log(gameObject.name + " go to " + target); string currentWayPoint = string.Empty; foreach (string wp in GameLogic.Instance.WaypointNames) { if (currentWayPoint == string.Empty) { currentWayPoint = wp; } //compares distances if (Vector3.Distance(transform.position, GameLogic.Instance.Waypoints[wp]) <= Vector3.Distance(transform.position, GameLogic.Instance.Waypoints[currentWayPoint])) { currentWayPoint = wp; } } List <Vector3> objsToFollow; objsToFollow = new List <Vector3>(); objsToFollow.Add(GameLogic.Instance.Waypoints[currentWayPoint]); objsToFollow.Add(GameLogic.Instance.Waypoints[currentWayPoint + "_Out"]); objsToFollow.Add(GameLogic.Instance.Waypoints[currentWayPoint + "_In"]); objsToFollow.Add(GameLogic.Instance.Waypoints[target + "_In"]); objsToFollow.Add(GameLogic.Instance.Waypoints[target + "_Out"]); objsToFollow.Add(GameLogic.Instance.Waypoints[target]); _pathWalker.SetWayPoints(objsToFollow, _speed); }