Пример #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Math for time to percentage
        float time =
            Mathf.Floor(100 -
                        ((Time.fixedTime - fixedTimeOnDeath) * 100 / timeLimitSeconds));

        // Visual cues
        timerImage.fillAmount -= Time.deltaTime / timeLimitSeconds;
        timerText.text         = $"{time.ToString()} %";

        // Timer ended
        if (time <= 0)
        {
            time = 0;
            timerImage.fillAmount = 1;
            imgAnim.SetBool("Warning", false);

            // Disable player
            //GameOver();
            gameManager.RestartLvl();
        }
        else if (time <= 30)
        {
            imgAnim.SetBool("Warning", true);
        }
    }
Пример #2
0
    // Collisions
    private void OnCollisionEnter2D(Collision2D col)
    {
        moving = false;
        DisableDirectionalColliders();

        if (col.collider.tag == "Obstacle")
        {
            rb.velocity = new Vector2(0f, 0f);
            //gm.CameraShake(0.01f, 0.02f);
            anim.speed = 0;
            onWater    = false;
        }

        else if (col.collider.tag == "Hazard")
        {
            anim.Play("Death");
            anim.speed = 1;
            gm.CameraShake(0.4f, 0.4f);
            rb.velocity = new Vector2(0f, 0f);
            gm.RestartLvl();
        }

        else if (col.collider.tag == "Water" && !onWater)
        {
            onWater     = true;
            rb.velocity = new Vector2(0f, 0f);
            anim.speed  = 0;
        }
    }