Exemple #1
0
    private void Update()
    {
        if (!gameOver)
        {
            timePassed += Time.deltaTime;

            if (timePassed >= timePerGame)
            {
                List <Product> list = new List <Product>();

                for (int i = 0; i < boxes.Count; i++)
                {
                    if (boxes[i].myProduct)
                    {
                        list.Add(boxes[i].myProduct);
                    }

                    else
                    {
                        Debug.Log("Checkea los productos pisha que hay alguno con producto nulo");
                    }
                }

                albaran.SetActive(true);
                Product_List_Manager.Instance.Initialize(list.ToArray());
                fadeOut.SetTrigger("FadeOut");
                audioMixer.TransitionToSnapshots(new AudioMixerSnapshot[1] {
                    audioMixer.FindSnapshot("MuteEverythingButMusic")
                }, new float[1] {
                    1f
                }, 0f);
                gameOver = true;
                return;
            }

            EvaluateWeights();

            if (!weightProblem)
            {
                timePassedSinceWeightProblem += Time.deltaTime;

                if (timePassedSinceWeightProblem >= timeForWeightProblem)
                {
                    timePassedSinceWeightProblem = 0;

                    StartWeightProblem();

                    weightProblem = true;

                    lightSwitch.SwitchOnLights();
                }
            }

            timePassedSinceAngleProblem += Time.deltaTime;

            if (timePassedSinceAngleProblem >= timeForAngleProblem)
            {
                timePassedSinceAngleProblem = 0;

                StartAngleProblem();

                lightSwitch.SwitchOnLights();
            }

            RotatePlane();

            if (Vector3.Angle(Vector3.up, plane.transform.forward) >= angleLost)
            {
                fadeOut.SetTrigger("FadeOut");
                Invoke("ResetGame", 5f);
                audioSource.clip = planeCrash;
                audioSource.Play();
                audioMixer.TransitionToSnapshots(new AudioMixerSnapshot[1] {
                    audioMixer.FindSnapshot("MuteEverything")
                }, new float[1] {
                    1f
                }, 0f);
            }

            if (Vector3.Angle(Vector3.up, plane.transform.forward) >= angleAlarm && !moreThanXAngle)
            {
                screenEvents.SetRotationAlarm(ScreenEvents.State.On);
                moreThanXAngle = true;
            }

            else if (Vector3.Angle(Vector3.up, plane.transform.forward) < angleAlarm && moreThanXAngle)
            {
                screenEvents.SetRotationAlarm(ScreenEvents.State.Solution);
                moreThanXAngle = false;
            }

            if (weightProblem)
            {
                timePassedInWeightProblem += Time.deltaTime;

                if (timePassedInWeightProblem >= timeWeightProblem)
                {
                    timePassedInWeightProblem    = 0;
                    timePassedSinceWeightProblem = 0;
                    weightProblem = false;
                    fadeOut.SetTrigger("FadeOut");
                    Invoke("ResetGame", 5f);
                    audioSource.clip = planeCrash;
                    audioSource.Play();
                    audioMixer.TransitionToSnapshots(new AudioMixerSnapshot[1] {
                        audioMixer.FindSnapshot("MuteEverything")
                    }, new float[1] {
                        1f
                    }, 0f);
                }
            }

            if (!weightProblem && !moreThanXAngle)
            {
                lightSwitch.SwitchOffLights();
            }
        }
    }