Esempio n. 1
0
    IEnumerator NightLoop()     //THE LOOP THAT COUNTS THE TIME AND THEN ENDS
    {
        foreach (BusStop BS in AllStops)
        {
            BS.Closed = (Random.value < GameSettings.ClosedChance);
            BS.GenerateNPCs();
        }

        Debug.Log("Night Started");

        Bus.ClearPassengers();
        Bus.Fuel = Bus.MaxFuel;
        Bus.GetComponent <Rigidbody>().velocity        = Vector3.zero;
        Bus.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        Bus.transform.position = M.Spawn.position;
        Bus.transform.rotation = M.Spawn.rotation;
        Bus.Unconscious        = false;

        MUI.StartMoney = GameSettings.SC.GetMoney();
        MUI.TopSpeed   = 0f;
        MUI.Fines      = 0;

        Bus.SetFrozen(false);

        TimeIndex = 0;

        if (GameObject.FindWithTag("Camera").transform.childCount > 0)
        {
            GameObject.FindWithTag("Camera").transform.GetChild(0).GetComponent <DashObject>().RemoveFromHands();
        }

        Rigidbody r = Bus.GetComponent <Rigidbody>();

        while (TimeIndex < GameSettings.NightDuration)
        {
            if (!Bus.B.isWarning)
            {
                Bus.B.WarningText.fontSize = 0.02f;

                if ((GameSettings.NightDuration - TimeIndex) > 0)
                {
                    Bus.B.WarningText.text = (GameSettings.NightDuration - TimeIndex).ToString();
                }
                else
                {
                    Bus.B.WarningText.text = "DONE";
                }
            }

            if (!Bus.BusStopped)
            {
                TimeIndex++;
            }
            yield return(TickSpeed);

            if (r.velocity.magnitude > MUI.TopSpeed)
            {
                MUI.TopSpeed = r.velocity.magnitude;
            }
        }

        while (Bus.BusStopped)
        {
            Debug.Log("NIGHT POSTPONED FOR BUS");
            yield return(null);
        }


        Bus.B.PlayAlarm();

        yield return(new WaitForSeconds(3f));

        MUI.ShowResultsMenu();
    }