public ViewingLocation getNewLocation([CanBeNull] ViewingLocation oldLocation) { int[] weights = new int[ViewingLocations.Items.Count]; int weightsSum = 0; for (int i = 0; i < weights.Length; i++) { if (oldLocation == ViewingLocations.Items[i]) { weights[i] = 0; } else if (oldLocation != null && oldLocation.Area == ViewingLocations.Items[i].Area) { weights[i] = 6; } else if (ViewingLocations.Items[i].Area == 0) //Exit { if (oldLocation == null) { weights[i] = 0; } else { weights[i] = (int)(bots.Items.Count * LeaveWeight); } } else { weights[i] = 1; } weightsSum += weights[i]; } int randomRoll = Random.Range(0, weightsSum); for (int i = 0; i < weights.Length; i++) { if (randomRoll < weights[i]) { return(ViewingLocations.Items[i]); } randomRoll -= weights[i]; } Debug.Log("ERROR: Location visited twice!"); return(oldLocation); }
public void StartWalking(Vector3?location = null) { if (location == null) { _destination = _navigationController.getNewLocation(_destination); if (_destination.Area == 0) //Exit { GetComponent <MeshRenderer>().material.color = Color.red; _leaving = true; } float minX = _destination.transform.localPosition.x - _destination.transform.localScale.x / 2; float maxX = _destination.transform.localPosition.x + _destination.transform.localScale.x / 2; float minZ = _destination.transform.localPosition.z - _destination.transform.localScale.z / 2; float maxZ = _destination.transform.localPosition.z + _destination.transform.localScale.z / 2; location = new Vector3(Random.Range(minX, maxX), _destination.transform.localPosition.y, Random.Range(minZ, maxZ)); } _navMeshAgent.SetDestination((Vector3)location); _walking = true; }