Search Unity

Making endless quiz game

Discussion in 'Scripting' started by LDPham, Mar 21, 2019.

  1. LDPham

    LDPham

    Joined:
    Mar 18, 2018
    Posts:
    13
    Code (CSharp):
    1. public class ClassWord : MonoBehaviour {
    2.  
    3.  
    4. private GameObject [] gameWords;
    5. private int randomNum;
    6.  
    7.  
    8. public Start()
    9. {
    10.  
    11. randomNum = Random.Range(0.gameWords.Length)
    12.  
    13. }
    14.  
    15. public void SpawnWord()
    16.         GameObject go = Instantiate(prefab[prefabNumber], spawnPos) as GameObject;
    17.  
    18.         return;
    19. }
    20. }
    21.  
    22.  
    23.  
    24.  
    25. Public Class GameManager: Monobehaiour{
    26.  
    27. public float maxTime = 5f;
    28.     public float timesLeft;
    29.  
    30.     pubic GameObject thedeathmenu;
    31.  
    32.  
    33.  
    34.     void Start () {
    35.         timerbar = GetComponent<Image> ();
    36.         timesLeft = maxTime;
    37.  
    38.  
    39.     }
    40.  
    41.  
    42.  
    43.     void Update () {
    44.    
    45.         if
    46.             (timesLeft > 0) {
    47.             timesLeft -= Time.deltaTime;
    48.             timerbar.fillAmount = timesLeft / maxTime;
    49.        
    50.         }
    51.             else
    52.         {
    53.             if
    54.                 (timesLeft <= 0){
    55.  
    56.                 gmeOverScreen.enable(true);          
    57.             }
    58.    
    59.         }
    60.     }
    61. }*/
    Code (CSharp):
    1.      public void OnClickRed()
    2.     {
    3.         if (gameObject.CompareTag("red"))
    4.             ScoreScirpt.scorevalue++;
    5.         else
    6.             ScoreScirpt.scorevalue--;
    7.         EndDisplay.SetActive(true);
    8.     }
    9.  
    10.  
    11.      
    12.  
    13.         public void OnClickYellow()
    14.         {
    15.             if (gameObject.CompareTag("yellow"))
    16.             ScoreScirpt.scorevalue++;
    17.         else
    18.              EndDisplay.SetActive(true);
    19.     }
    20.  
    21.  
    22.  
    23.         public void OnClickGreen()
    24.     {
    25.         if (gameObject.CompareTag("green"))
    26.         ScoreScirpt.scorevalue++;
    27.      else
    28.         EndDisplay.SetActive(true);
    29. }
    30.  
    31.  
    32.  
    33.     public void OnClickOrange()
    34.     {
    35.         if (gameObject.CompareTag("orange"))
    36.             ScoreScirpt.scorevalue++;
    37.         else
    38.             EndDisplay.SetActive(true);
    39.     }
    40.  
    41.  
    42.  
    43.      public void OnClickBlk()
    44. {
    45.     if (gameObject.CompareTag("black"))
    46.         ScoreScirpt.scorevalue++;
    47.     else
    48.             EndDisplay.SetActive(true);
    49.  
    50.     }
    51.  
    52.  
    53. }*/
    54. for buttond
    ?Instead of using quiz questions im using prefabs. I am trying to put total of 6 different buttons that stays the entire game. Would like to use game objects and use same tags instantiate loop? Have a total of 36 different prefabs. Not sure how would work put in a "container" and one prefabs starts at awake. Then must click button within amount seconds and if pressed right then would want to change to another prefab. And add score.

    1. dd
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Any particular reason why you need to cycle through prefabs? It seems like you could just change the values of certain fields, such as the quiz text, and re-evaluate the correct answer every time the question changes.