public void StartTakeoff(Scr_Airport airport) { if (currentBaseState == BaseState.Parked) { currentAirport = airport; SetState(BaseState.TakingOff); takingOffStep = 0; } else { Debug.Log("The plane must be landed in order to take off!"); } }
void Check() { if (currentBaseState == BaseState.Idle) // when the basestate is set to idle, it means the plane has successfully taken off { if (airport != null) { airport = Scr_AirportHandler.instance.GetRandomOtherNeutralOrFriendlyAirport(0, airport.transform.position); // find another airport } else { airport = Scr_AirportHandler.instance.GetClosestAirport(transform.position); } StartLanding(airport);// and land there } }
public Scr_Airport GetClosestAirport(Vector3 pos) { Scr_Airport currentClosest = null; float currentDistance = -1; foreach (Scr_Airport a in airports) { float dist = Vector3.Distance(a.transform.position, pos); if (currentDistance == -1 || dist < currentDistance) { currentClosest = a; currentDistance = dist; } } return(currentClosest); }
public void StartLanding(Scr_Airport airport) { if (airport != null) { if (currentBaseState != BaseState.Landed && currentBaseState != BaseState.Landing) { currentAirport = airport; SetState(BaseState.Landing); landingStep = 0; } } else { SetState(BaseState.Idle);//airport not found } }
public Scr_Airport GetClosestNeutralOrFriendlyAirport(Vector3 pos, int team) { Scr_Airport currentClosest = null; float currentDistance = -1; foreach (Scr_Airport a in airports) { if (a.team == 0 || a.team == team) // neutral or same team { float dist = Vector3.Distance(a.transform.position, pos); if (currentDistance == -1 || dist < currentDistance) { currentClosest = a; currentDistance = dist; } } } return(currentClosest); }