Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mrjoners · Oct 07, 2016 at 07:41 AM · quiz

Quiz Game Score

Hi..... i'm new in unity and i want to make a quiz game and here is the script

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
 
     public Question[] questions;
     private static List<Question> unansweredQuestions;
 
     private Question currentQuestion;
 
     [SerializeField]
     private Text factText;
 
     [SerializeField]
     private Text TrueAnswerText;
     [SerializeField]
     private Text FalseAnswerText;
 
     [SerializeField]
     private Animator animator;
 
     [SerializeField]
     private float TimeBetweenQuestions = 1f;
 
     void Start()
     {
         if (unansweredQuestions == null || unansweredQuestions.Count == 0)
         {
             unansweredQuestions = questions.ToList<Question>();
         }
         SetCurrentQuestion();
     }
 
     void SetCurrentQuestion()
     {
         int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
         currentQuestion = unansweredQuestions[randomQuestionIndex];
 
         factText.text = currentQuestion.fact;
 
         if (currentQuestion.isTrue)
         {
             TrueAnswerText.text = "Hebat";
             FalseAnswerText.text = "Maaf";
         }else
         {
             TrueAnswerText.text = "Maaf";
             FalseAnswerText.text = "Hebat";
         }
     }
 
     void CallGameOverScene()
     {
         SceneManager.LoadScene("GameOverScene");
         Application.LoadLevel("GameOverScene");
     }
 
     IEnumerator TransitionToNextQuestion()
     {
         unansweredQuestions.Remove(currentQuestion);
 
         yield return new WaitForSeconds(TimeBetweenQuestions);
 
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }
 
     public void UserSelectTrue()
     {
         animator.SetTrigger("Benar");
         if (currentQuestion.isTrue)
         {
             Debug.Log("Hebat!");
             StartCoroutine(TransitionToNextQuestion());
         }
         else
         {
             Debug.Log("Maaf");
             CallGameOverScene();
         }
 
     }
 
     public void UserSelectFalse()
     {
         animator.SetTrigger("Salah");
         if (!currentQuestion.isTrue)
         {
             Debug.Log("Hebat!");
             StartCoroutine(TransitionToNextQuestion());
         }
         else
         {
             Debug.Log("Maaf");
             CallGameOverScene();
         }
 
     }
 }

how to make a scoring and final score on game over scene ? Thx before Ps; i'm following tutorial brackeys to make this script :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sonsho · Jan 23, 2020 at 11:29 AM 0
Share

Hello I have the same issue, when I added the "Score.scoreValue += 1;" into The IEnumerator the score keeps increasing no matter if it's correct or false. I then tried adding it within the animator trigger function, it works now only when it's a correct answer but if you spam click the score keeps increasing. Any help would be appreciated.

 public void UserSelectTrue()
     {
 
         animator.SetTrigger("True");
         if (currentQuestion.isTrue)
         {
 
             Debug.Log("CORRECT");
             Score.scoreValue += 1;
 
         }
         else
         {
             Debug.Log("FALSE");
 
         }
 
         StartCoroutine(TransitionToNextQuestion());
     }
 


1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AKASH135 · Jul 14, 2017 at 12:16 AM

create a score script like this

using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;

public class ScoreScript : MonoBehaviour {

 public static int scoreValue = 0;
 Text score;
 // Use this for initialization
 void Start () {
     score = GetComponent<Text> ();
 }
 
 // Update is called once per frame
 void Update () {
     score.text = "Answered :" +scoreValue;
 }


}

go to gamemanager script add in

IEnumerator TransitionToNextQuestion() { unansweredQuestions.Remove(currentQuestion);

      yield return new WaitForSeconds(TimeBetweenQuestions);

      ScoreScript.scoreValue += 1;

      SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C# simple timer? 2 Answers

Hi, I making the quiz for my research. How can change the quiz image by question ID or submit Button? 1 Answer

How to randomize non-repaeting question? 0 Answers

quiz game how to store questions 2 Answers

How to turn a label off as the next button is pressed in a Quiz game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges