public void SetState(BaseState b) { currentBaseState = b; if (currentBaseState == BaseState.TakingOff) { landingSpot = null; hasLandingSpot = false; currentAirport.ClearLandingSpot(this); // clear the current parking spot so other planes can land } if (currentBaseState == BaseState.Idle) { idlePosition = transform.position; } }
void Landing() { targetPos = currentAirport.landingSpots[landingStep].position; // fly towards the airport if (Vector3.Distance(transform.position, targetPos) < tooCloseDistance) // reached the target, next landing step { if (hasLandingSpot) { landingStep++; if (landingStep > 4) // reached the last landing step { Landed(); } } else { if (gettingDistanceFromTarget == false) { landingSpot = currentAirport.GetFreeSpot(this); // try to reserve a landing spot from the airport if (landingSpot != null) { hasLandingSpot = true; // found a free landing spot } else { GetDistance(); // airport is full, wait and fly in circles } } } } if (landingStep >= 4) { currentMovementSpeed = Mathf.MoveTowards(currentMovementSpeed, 10, 5f * Time.deltaTime); // slow down } else { currentMovementSpeed = Mathf.MoveTowards(currentMovementSpeed, movementSpeed, 10f * Time.deltaTime); } }