I did challenge like this

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;


public class Timer : MonoBehaviour
{

    [SerializeField] float timeToCompleteQuestion = 30.0f;
    [SerializeField] float timeToShowCorrectAnswer = 10.0f;
    float timerValue;

    public bool isAnsweringQuestion = false;

    void Update()
    {
        if (isAnsweringQuestion == true)
        {
            UpdateTimer();
        }
        else if (isAnsweringQuestion == false)
        {
            CorrectAnswerTime();
        }
    }

    void CorrectAnswerTime()
    {
        timerValue -= Time.deltaTime;  
        Debug.Log("Check Correct Answer : in " + timerValue + " second(s)!");
        if (timerValue <= 0)
        {
            timerValue = timeToCompleteQuestion;
            isAnsweringQuestion = true;
        }
    }

    void UpdateTimer()
    {
        timerValue -= Time.deltaTime;
        Debug.Log("Choose the answer in ★" + timerValue + "★ second(s)!");
        if (timerValue <= 0)
        {
            timerValue = timeToShowCorrectAnswer;
            isAnsweringQuestion = false;
        }

    }
}

I am a super beginner.
It’s been over half a year since I learned to code. :smiley:

I understand my variable naming sense is terrible, and I tried to name it appropriately… but it’s not easy :grin: :thinking: :grin:

I want to separate the function according to its usage,
but after seeing Gray’s solution, I thought his code is easier than mine.

I am super enjoying the class! Thank you for your exciting lesson!
Let’s go let’s go let’s go~~~

Privacy & Terms