Example #1
0
    IEnumerator SpaceLanding(bool isLanding, SpaceLandingCallback callback)
    {
        while (launchInProgress)
        {
            yield return(null);
        }

        launchInProgress = true;

        var landingFx = Instantiate(spaceLandingPrefab, transform);

        landingFx.transform.localPosition = Vector3.zero;
        var landingFloor = landingFx.transform.Find("Landing Floor").gameObject;

        landingFloor.transform.SetParent(transform.parent);
        landingFloor.transform.localPosition = originalPos + Vector3.down * 2;

// If we are landing, start from the space and go down.
// If we are lifting off, start from zero and go up.
        float curHeight    = isLanding ? SpaceLandingHeight : 0;
        float curSpeed     = isLanding ? SpaceLandingStartSpeed : 0;
        float acceleration = isLanding ? SpaceLandingDeceleration : SpaceLandingDeceleration;

        while (isLanding ? curHeight > 0 : curHeight < SpaceLandingHeight)
        {
            SetHeight(originalPos, curHeight);
            curHeight += curSpeed * Time.deltaTime;
            curSpeed  += acceleration * Time.deltaTime;

            yield return(null);
        }

        SetHeight(originalPos, isLanding ? 0 : SpaceLandingHeight);

        landingFx.transform.Find("Landing Rocket").GetComponent <ParticleSystem>().Stop();
        StartCoroutine(DestroyLandingFx(landingFx, landingFloor));


        yield return(new WaitForSeconds(1f));

        launchInProgress = false;
        callback?.Invoke();
    }
Example #2
0
 public void DoSpaceLiftoff(SpaceLandingCallback callback)
 {
     StartCoroutine(SpaceLanding(false, callback));
 }
Example #3
0
 public void DoSpaceLanding(SpaceLandingCallback callback)
 {
     StartCoroutine(SpaceLanding(true, callback));
 }