Example #1
0
    void Update()
    {
        if (over)
        {
            return;
        }

        bool currentlyAllOn  = true;
        bool currentlyAllOff = true;

        foreach (LightsOutButton b in buttons)
        {
            currentlyAllOn  = currentlyAllOn && b.isOn;
            currentlyAllOff = currentlyAllOff && !b.isOn;
        }

        //Win
        if (currentlyAllOn)
        {
            buttonSrc.clip = winClip;
            buttonSrc.Play();

            StartCoroutine(GameWon());
            over = true;
        }

        //Lose
        if (currentlyAllOff)
        {
            player.GetComponent <Player>().PowerFailure();
            chooser.Stop();
            over    = true;
            enabled = false;
        }
    }
    void LateUpdate()
    {
        if (won)
        {
            return;
        }
        if (currentPressureValue != targetPressureValue)
        {
            currentPressureValue = Mathf.Lerp(currentPressureValue, targetPressureValue, (1 / lerpTime) * Time.deltaTime);
            if (Mathf.Abs(currentPressureValue - targetPressureValue) < 0.001f)
            {
                currentPressureValue = targetPressureValue;
            }
        }

        indicator.value = currentPressureValue;

        if (currentPressureValue >= 0.65f)
        {
            loseTimer = Mathf.Max(0, loseTimer - Time.deltaTime);
        }
        else
        {
            loseTimer = Mathf.Min(maxLoseTime, loseTimer + Time.deltaTime * 2);
        }

        timeProgressor.SetValue(maxLoseTime - loseTimer);
        src.pitch = 1 + timeProgressor.Value / maxLoseTime;

        //Lose
        if (loseTimer <= 0)
        {
            GameObject.FindGameObjectWithTag("Player").GetComponent <Player>().PressureFailure();
            chooser.Stop();
            src.Stop();
            this.enabled = false;
        }

        //Win
        if (currentPressureValue == targetPressureValue && targetPressureValue == 0.6f)
        {
            GameEventMessage.SendEvent("GameWon");
            StartCoroutine(GameWon());
            won = true;
        }
    }