Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 familiaguiocortes · Aug 23, 2020 at 10:42 PM · buttonscenegamebuttonsscenes

Go to next scene when correct answer

Hi, so I am new on using unity and I am trying to do a quiz game and I have made 6 scenes and on each of them there is a question and four buttoms and one is the correct answer, I am not sure on how to make it change scene when I click the correct answer or if I can make something say "correct" and go to the next scene or on the opposite if they click the incorrect buttom that it says "try again" and then they have to try again, can someone please help me?

I know this is a stupid question but as I said before I am a very confused begginer so if someone helps me I will thank them for life.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FeedMyKids1 · Aug 23, 2020 at 10:59 PM

Go to File/Build Settings and make sure to add all the scenes in your project.

Create a script called SceneLoader and put using UnityEngine.SceneManagement;

 public class SceneLoader: MonoBehaviour
 {
 
       //Call something like this when someone gets the answer right
 public void TryLoadNextScene() 
     {
         int currentScene = SceneManager.GetActiveScene().buildIndex;
 
         if (currentScene < SceneManager.sceneCount - 1)
             SceneManager.LoadScene(currentScene + 1);        
     }
 }

Make sure to attach the script to something in the scene and reference it so that you can call TryLoadNextScene when you the answer is correctly answered.

Comment
Add comment · Show 5 · 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
avatar image familiaguiocortes · Aug 25, 2020 at 01:34 AM 0
Share

Thank you so much!! I already make sure all the scenes where added, created the script with the UnityEngine... and pasted the script, but I don't know how can I reference it?? like how can make the script work and change the scene when the click the correct answer button??

avatar image FeedMyKids1 familiaguiocortes · Aug 25, 2020 at 10:51 AM 0
Share

You could make it a Singleton and reference it from anywhere or you could put it directly on your Game$$anonymous$$anager.

I would have three components - QuestionAnswerUI, Game$$anonymous$$anager, and SceneLoader:

Your Game$$anonymous$$anager tells your questionAnswerUI.ShowQuestion (Question q) [supposing that also passes the answers] and when the player clicks a button, QuestionAnswerUI calls Game$$anonymous$$anager.ClickedButton (int buttonNum) and you check if answer[buttonNum] is correct. If it is you do all your reward logic and calls back to QuestionAnswerUI.EnableNextSceneButton().

You click that and you have something like

 class QuestionAnswerUI 
 {
 private void Start ()
 {
 nextScene.onClick.AddListener (delegate{ SceneLoader.Instance.TryLoadNext() ;});
 
 int i = 0;
 foreach(Button b in answerButtons)
 {
      int index = i; //$$anonymous$$ust create new int so as not to pass pointer to i
       b.onClick.AddListener (delegate { Game$$anonymous$$anager.ClickedButton(index) ;});
       i++;
 }
 }
 
 public void ShowQuestion (Question q)
 {
 //Post question text
 
 //Load answer texts into buttons and enable them
 }
 
 public void EnableNextSceneButton() => nextScene.enabled = true;
 
 }
avatar image familiaguiocortes FeedMyKids1 · Aug 26, 2020 at 02:40 AM 0
Share

Again thank you so much!! you really do help, but I messed up and I don't know how but now I can't even add the scripts to the Game manager :( I know this is a lot to ask but is there any way I can send you my project and you can check it out and tell me the things I did wrong and help me, please? If you can't I will completly understand it and (I'm not really sure how this works) but I gave you a point for helping me so much...again thanks!!

Show more comments
avatar image
-1

Answer by hkl788954 · Aug 27, 2020 at 05:25 AM

Ford Feedback Survey – If you are searching for genuine details on Ford Customer Satisfaction Survey to share your loyal feedback about Ford Survey.

SEE HERE:https://surveyexpert.info/ford-survey/

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
avatar image
0

Answer by Aviryx · Aug 23, 2020 at 11:48 PM

You could just replicate this for each scene if you want something basic.


 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;

 public class SceneOneManager : MonoBehaviour
 {
     public GameObject incorrectAnswerPanel_UI;

     public Button answerOne;
     public Button answerTwo;
     public Button answerThree;

     void Start()
     {
         answerOne.onClick.AddListener(IncorrectAnswer);
         answerTwo.onClick.AddListener(IncorrectAnswer);
         answerThree.onClick.AddListener(CorrectAnswer);
     }

     private void IncorrectAnswer()
     {
         incorrectAnswerPanel_UI.SetActive(true);
     }

     private void CorrectAnswer()
     {
         StartCoroutine(LoadNextScene());
     }

     IEnumerator LoadNextScene()
     {
         AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(2);

         while (!asyncLoad.isDone)
         {
             yield return null;
         }
     }
 }
Comment
Add comment · Show 3 · 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
avatar image familiaguiocortes · Aug 25, 2020 at 01:28 AM 0
Share

Thank you so much! And where can I put this script? on a Game$$anonymous$$anager object or somewhere else? and then I have to put sometyhing on the buttons? Sorry if this are stupid questions, but again I am a begginer :(

avatar image familiaguiocortes familiaguiocortes · Aug 25, 2020 at 01:46 AM 0
Share

And I tried the script and Unity says Error "The type or name space "IEnumerator" could not be found, can you please help me, thank you in advance

avatar image FeedMyKids1 familiaguiocortes · Aug 25, 2020 at 11:25 AM 1
Share

For IEnumerator, be sure to have "using System.Collections; "

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

220 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a problem to build the game in the Hierarchy without loading scenes at all ? 0 Answers

How to mute my volume 2 Answers

LoadLevel easy i know, but not working. 1 Answer

This script is not displaying scenes in unity properly. How would you fix it? 0 Answers

buttons not being able to be clicked? 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