Search Unity

Question Button color change and coundown timer

Discussion in 'UGUI & TextMesh Pro' started by nanelisinden, Sep 9, 2020.

  1. nanelisinden

    nanelisinden

    Joined:
    Aug 11, 2020
    Posts:
    3
    l

    Code (CSharp):
    1. using JetBrains.Annotations;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7. using Random = UnityEngine.Random;
    8.  
    9. public class Yarisma : MonoBehaviour {
    10.  
    11.     public Text questionName, answerA, answerB, answerC, answerD, scoreTxt, timeTxt;
    12.     Sorular sr;
    13.     public List<bool> answered;
    14.  
    15.     //private bool deger;
    16.     public string timeText;
    17.     public int answer,score;
    18.     public float time;
    19.     //[SerializeField] private Color correctCOl, wrongCOl, normalCOl;
    20.  
    21.  
    22.  
    23.     [SerializeField]
    24.     private GameObject RetryUI;
    25.  
    26.     [SerializeField]
    27.     private GameObject TimeUI;
    28.  
    29.     void Start () {
    30.         sr = GetComponent<Sorular>();
    31.         for (int i = 0; i < sr.sorular.Count; i++)
    32.         {
    33.             answered.Add(false);
    34.         }
    35.         soruEkle();
    36.      
    37.     }
    38.  
    39.  
    40.     void Update () {
    41.      
    42.         if (time > 0)
    43.         {
    44.             time -= Time.deltaTime;
    45.             timeTxt.text = time.ToString("00");
    46.         }
    47.         else
    48.         {
    49.          
    50.             TimeUI.SetActive(true);
    51.         }
    52.      
    53.     }
    54.  
    55.  
    56.  
    57.  
    58.  
    59.     public void soruEkle() {
    60.         for (int i = 0; i < answered.Count; i++)
    61.         {
    62.             if (answered[i] == false)
    63.             {
    64.                 int soruSayi = Random.Range(0, answered.Count);
    65.                 if (answered[soruSayi] == false)
    66.                 {
    67.                     answered[soruSayi] = true;
    68.                     score++;
    69.                     time = 20;
    70.                     scoreTxt.text = "Soru: "+score;
    71.                     questionName.text = sr.sorular[soruSayi].soruismi;
    72.                     answerA.text = sr.sorular[soruSayi].cevapa;
    73.                     answerB.text = sr.sorular[soruSayi].cevapb;
    74.                     answerC.text = sr.sorular[soruSayi].cevapc;
    75.                     answerD.text = sr.sorular[soruSayi].cevapd;
    76.                     answer = sr.sorular[soruSayi].cevap;
    77.  
    78.  
    79.                 }else
    80.                 {
    81.                     soruEkle();
    82.                 }
    83.  
    84.                 break;
    85.             }
    86.             if(i == answered.Count - 1 )
    87.             {
    88.                 Debug.Log("Win");
    89.             }
    90.         }
    91.  
    92.  
    93.      
    94.     }
    95.  
    96.     public void cevapVer(int value)
    97.     {
    98.      
    99.         if (value == answer)
    100.         {
    101.          
    102.             soruEkle();
    103.         }
    104.         else
    105.         {
    106.          
    107.             RetryUI.SetActive(true);
    108.          
    109.          
    110.          
    111.          
    112.          
    113.          
    114.         }
    115.     }
    116.  
    117.  
    118.  
    119.  
    120. }
    121.  
     
    Last edited: Sep 9, 2020
  2. nanelisinden

    nanelisinden

    Joined:
    Aug 11, 2020
    Posts:
    3
    I am developing quiz game, and I need to set button color change, but I cannot do that. Also, How can I stop the countdown timer?? It does not mean pause a game.After giving a wrong answer, countdown timer should stop. Please help.