private void Awake() { _playerGameObject = GameObject.FindGameObjectWithTag("Player"); if (_playerGameObject == null) { Debug.LogError("Player game object not found."); } _pet = GetComponent <Pet>(); _agent = GetComponent <NavMeshAgent>(); _animator = GetComponent <Animator>(); _waypoints = ScriptableObject.CreateInstance <WaypointsAsset>(); _waypoints.Waypoints = PoissonDiscSampling.Generate3D(WaypointRadius, new Vector2(PlayGroundTransform.localScale.x, PlayGroundTransform.localScale.z)); List <Vector3> navMeshWaypoints = new List <Vector3>(); for (int i = 0; i < _waypoints.Waypoints.Count; i++) { NavMeshHit hit; if (NavMesh.SamplePosition(_waypoints.Waypoints[i], out hit, 100f, NavMesh.AllAreas)) { navMeshWaypoints.Add(hit.position); } } _waypoints.Waypoints = navMeshWaypoints; }