Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (playIntro)
        {
            IntroSequence();
            mainThrustOn = true;

            if (rb.velocity.magnitude > speedLimit)
            {
                thrustMulti = 0f;
            }
            else
            {
                thrustMulti = 1f;
            }
        }
        else if (startGame)
        {
            if (!isConnected)
            {
                // Reset speed multi, drag, cargo spawning, and ui elements - they'll be set by tests below
                thrustMulti            = 1f;
                rb.drag                = defaultDrag;
                speedLimitText.enabled = false;
                moonNameText.enabled   = false;
                stationText.enabled    = false;
                outOfFuel.enabled      = false;

                // deactivate cargo spawning (but leave cargo despawning on)

                // Turn off the warning text unless we're getting out of bounds
                warningText.enabled = false;
                if (transform.position.magnitude > 9999f)
                {
                    warningText.enabled = true;
                }

                // Display the ship's speed
                speedReadout.text = Mathf.Round(rb.velocity.magnitude * 100f).ToString() + "m/s";

                // Display remaining fuel
                fuelReadout.text = "Fuel: " + Mathf.Round(fuel).ToString();

                // Update the closest important objects
                ClosestMoon();
                ClosestSpaceStation();

                // Check our distance from those objects and do things if we cross thresholds
                CheckMoon();
                CheckStation();

                // Check for any boxes nearby that we can collect
                CheckBoxes();

                // Keep the ship under the max speed limit at all times
                if (rb.velocity.magnitude > maxSpeed)
                {
                    thrustMulti = 0f;
                }

                IceCollide(); // Occasionally makes ice explode off the ship (explains the drag in open space)

                // If we earn a threshold amount of money then trigger a new email (and update the threshold counter)
                if (wallet > prevThreshold + moneyThreshold)
                {
                    prevThreshold += moneyThreshold;
                    bool readyForNewEmail = emailHandler.NewEmail();
                    if (readyForNewEmail)
                    {
                        lastEmail  = emailHandler.CheckIfLastEmail();
                        emailAlert = true;
                    }
                }
            }
        }


        if (mainThrustOn)
        {
            ForwardThrusters();
            BurnFuel();
            if (engineActive)
            {
                engineSound.volume = 1f;
            }
        }
        else
        {
            engineSound.volume = 0f;
        }

        if (fuel < 1)
        {
            soundEffects.Alarm();
            mainThrustOn = false;
            // OUT OF FUEL
            outOfFuel.enabled = true;
            if (Input.GetKeyUp("1") && !stationText.enabled)
            {
                spaceStationHandler.LoadTom();
                ConnectToTom();
            }
        }

        if (movingCamera)
        {
            MoveCamera();
        }

        if (takeInput)
        {
            GetInput();
        }

        if (emailAlert)
        {
            soundEffects.Fanfare();
            emailAlert = false;
        }
    }