private void FindAndPathToFoodhall() { if (currentFoodhall == null) { List <FoodHall> allFoodhalls = new List <FoodHall>(BuildingPlacement.Instance.corePoolObject.GetComponentsInChildren <FoodHall>()); foreach (FoodHall foodHall in allFoodhalls) { if (foodHall.ReservePlace(myPolyNavAgent)) { currentFoodhall = foodHall; break; } } } if (currentFoodhall == null) { Debug.LogWarning("Student couldn't find a foodhall to eat in"); currentBehaviour = STUDENT_BEHAVIOUR.Wandering; return; } myPolyNavAgent.maxSpeed = 4; Vector3 foodLocation = currentFoodhall.transform.position; Vector2 destination = new Vector2(foodLocation.x, foodLocation.y); myPolyNavAgent.SetDestination(destination); }
private void ReturnToDormitory() { if (!myStudentAccommodationScript.myDormitory) { currentBehaviour = STUDENT_BEHAVIOUR.Wandering; return; } myPolyNavAgent.maxSpeed = 4; Vector3 dormLocation = myStudentAccommodationScript.myDormitory.transform.position; Vector2 destination = new Vector2(dormLocation.x + 1, dormLocation.y); myPolyNavAgent.SetDestination(destination); }
private void OnHourChange() { // Inside a building if (!myPolyNavAgent.enabled) { // Was learning, now leaving if (currentBehaviour == STUDENT_BEHAVIOUR.Learning && TimeManager.Instance.GetCurrentTimeslot() != TIMESLOT.TEACHING && currentClassroom) { currentClassroom.StudentExit(this); myStudentNeeds.isBusy = false; } // Was sleeping, now leaving else if (currentBehaviour == STUDENT_BEHAVIOUR.Sleeping && TimeManager.Instance.GetCurrentTimeslot() != TIMESLOT.SLEEPING && myStudentAccommodationScript.myDormitory) { myStudentAccommodationScript.myDormitory.StudentExit(this); myStudentNeeds.isSleeping = false; } // Was eating, now leaving else if (currentBehaviour == STUDENT_BEHAVIOUR.Eating && TimeManager.Instance.GetCurrentTimeslot() != TIMESLOT.EATING && currentFoodhall) { currentFoodhall.StudentExit(this); myStudentNeeds.isEating = false; } } // Time to sleep if (TimeManager.Instance.GetCurrentTimeslot() == TIMESLOT.SLEEPING && currentBehaviour != STUDENT_BEHAVIOUR.Sleeping) { currentBehaviour = STUDENT_BEHAVIOUR.Sleeping; myPolyNavAgent.Stop(); } // Nothing to do else if (TimeManager.Instance.GetCurrentTimeslot() == TIMESLOT.NONE && currentBehaviour != STUDENT_BEHAVIOUR.Wandering) { currentBehaviour = STUDENT_BEHAVIOUR.Wandering; myPolyNavAgent.Stop(); } // Time to go to class else if (TimeManager.Instance.GetCurrentTimeslot() == TIMESLOT.TEACHING && currentBehaviour != STUDENT_BEHAVIOUR.Learning) { currentBehaviour = STUDENT_BEHAVIOUR.Learning; myPolyNavAgent.Stop(); } // Time to eat else if (TimeManager.Instance.GetCurrentTimeslot() == TIMESLOT.EATING && currentBehaviour != STUDENT_BEHAVIOUR.Eating) { currentBehaviour = STUDENT_BEHAVIOUR.Eating; myPolyNavAgent.Stop(); } }
void OnEnable() { myPolyNavAgent.OnDestinationReached += ReachedDestination; //myPolyNavAgent.OnDestinationInvalid += MoveRandom; gameTime.OnHourIncrement += OnHourChange; if (TimeManager.Instance.GetCurrentTimeslot() == TIMESLOT.SLEEPING) { currentBehaviour = STUDENT_BEHAVIOUR.Sleeping; } else { currentBehaviour = STUDENT_BEHAVIOUR.Wandering; } }
private void FindAndPathToClassroom() { currentClassroom = BuildingPlacement.Instance.FindClassroom(myStudentStats.studentDesire); if (currentClassroom == null) { Debug.LogWarning("Can't find a classroom for " + myStudentStats.studentDesire.ToString()); currentBehaviour = STUDENT_BEHAVIOUR.Wandering; return; } myPolyNavAgent.maxSpeed = 4; Vector3 classLocation = currentClassroom.transform.position; Vector2 destination = new Vector2(classLocation.x + 2, classLocation.y); myPolyNavAgent.SetDestination(destination); }