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 DennisseCC · Mar 22, 2017 at 07:27 AM · if statement

what would be the if statement if the previous question loaded is repeated or equal to the same..

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

public class GameManager : MonoBehaviour { public Question[]questions; public Button[]bttn; public Button[]factbluff; public int life=5;

 private static List<Question>unansweredQuestions;
 private Question currentQuestion;


 public GameObject GameQuestionHolder;
 public GameObject GameAnswerHolder;
 public GameObject GameAnswer1Holder;
 public GameObject GameAnswer2Holder;
 public GameObject GamePauseHolder;
 public GameObject IncorrectAnswerHolder;
 public GameObject CorrectAnswerHolder;



 [SerializeField]
 private Text questiontext;

 [SerializeField]
 private Text answertext;

 [SerializeField]
 private Text answertext1;

 [SerializeField]
 private Text answertext2;
 [SerializeField]
 private Text lifenum;

 [SerializeField]
 private float timeBetweenQuestions = 1f;

 [SerializeField]
 private Animator animator;

 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];
     questiontext.text=currentQuestion.questionText;
 }

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

     yield return new WaitForSeconds (timeBetweenQuestions);

     SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
 }

 public void GamePause()
 {
     GamePauseHolder.SetActive (true);
     GameQuestionHolder.SetActive (false);
     GameAnswerHolder.SetActive (false);
     GameAnswer1Holder.SetActive (false);
     GameAnswer2Holder.SetActive (false);
     IncorrectAnswerHolder.SetActive (false);
     CorrectAnswerHolder.SetActive (false);

 }

 public void GameQuestion()
 {

     GameQuestionHolder.SetActive (true);
     GameAnswerHolder.SetActive (false);
     GameAnswer1Holder.SetActive (false);
     GameAnswer2Holder.SetActive (false);
     GamePauseHolder.SetActive (false);
     IncorrectAnswerHolder.SetActive (false);
     CorrectAnswerHolder.SetActive (false);
 }    

 public void GameMenu()
 {
     SceneManager.LoadScene ("GameMenu");
 }

 public void SelectBluffer()
 {
     
     GameAnswerHolder.SetActive (true);
     GameQuestionHolder.SetActive (false);
     GameAnswer1Holder.SetActive (false);
     GameAnswer2Holder.SetActive (false);
     GamePauseHolder.SetActive (false);
     IncorrectAnswerHolder.SetActive (false);
     CorrectAnswerHolder.SetActive (false);
     answertext.text = currentQuestion.answers [0].answerText;

 }
 public void SelectBluffer1 ()
 {
     
     GameAnswer1Holder.SetActive(true);
     GameQuestionHolder.SetActive (false);
     GameAnswerHolder.SetActive (false);
     GameAnswer2Holder.SetActive (false);
     GamePauseHolder.SetActive (false);
     IncorrectAnswerHolder.SetActive (false);
     CorrectAnswerHolder.SetActive (false);
     answertext1.text = currentQuestion.answers [1].answerText;

 }

 public void SelectBluffer2()
 {
         GameAnswer2Holder.SetActive (true);
         GameQuestionHolder.SetActive (false);
         GameAnswerHolder.SetActive (false);
         GameAnswer1Holder.SetActive (false);
         GamePauseHolder.SetActive (false);
         IncorrectAnswerHolder.SetActive (false);
         CorrectAnswerHolder.SetActive (false);
         answertext2.text = currentQuestion.answers [2].answerText;

 }

 public void Fact()
 {
     if (currentQuestion.answers [0].isTrue ) 
     {
         CorrectAnswerHolder.SetActive (true);
         lifenum.text = "Life : " + life.ToString ();
     }
     else
     {
         IncorrectAnswerHolder.SetActive (true);

     }
     StartCoroutine (TransitionToNextQuestion ());
 }


 public void Bluff()
 {
     if (!currentQuestion.answers [0].isTrue) 
     {
         
         CorrectAnswerHolder.SetActive (true);
     }
     else
     {
         
         IncorrectAnswerHolder.SetActive (true);
     }
     StartCoroutine (TransitionToNextQuestion ());
 }

 public void Fact1()
 {
     if (currentQuestion.answers [1].isTrue ) 
     {
         CorrectAnswerHolder.SetActive (true);
     }
     else
     {
         IncorrectAnswerHolder.SetActive (true);
     }
     StartCoroutine (TransitionToNextQuestion ());
 }


 public void Bluff1()
 {
     if (!currentQuestion.answers [1].isTrue) 
     {
         CorrectAnswerHolder.SetActive (true);
     }
     else
     {
         IncorrectAnswerHolder.SetActive (true);
     }
     StartCoroutine (TransitionToNextQuestion ());
 }

 public void Fact2()
 {
     if (currentQuestion.answers [2].isTrue ) 
     {
         CorrectAnswerHolder.SetActive (true);
     }
     else
     {
         IncorrectAnswerHolder.SetActive (true);
     }
     StartCoroutine (TransitionToNextQuestion ());
 }


 public void Bluff2()
 {
     if (!currentQuestion.answers [2].isTrue) 
     {
         CorrectAnswerHolder.SetActive (true);
     }
     else
     {
         IncorrectAnswerHolder.SetActive (true);
     }
     StartCoroutine (TransitionToNextQuestion ());
 }


}

Comment
Add comment · Show 3
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 Matt1000 · Mar 22, 2017 at 09:03 AM 0
Share

To be honest, I didn't get your question but i can sense that that's not very nice coding... Why dont you create 1 Fact and one Bluff with loops or checks the index of the question and uses it.

avatar image DennisseCC Matt1000 · Mar 22, 2017 at 09:14 AM 0
Share

I do agree with the both of you.. what should be the for loop code for the buttons?

avatar image sirjoan620 DennisseCC · Mar 22, 2017 at 09:26 AM 1
Share

You can use arrays.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ShadyProductions · Mar 22, 2017 at 09:07 AM

I do agree with Matt, this could be done alot cleaner. But to answer your question, you will need to keep 2 variables

 private Question currentQuestion;
 private Question previousQuestion;
 
 if (currentQuestion == previousQuestion) {
 //do whatever
 }
Comment
Add comment · Show 1 · 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 DennisseCC · Mar 22, 2017 at 09:13 AM 0
Share

I do agree with the both of you.. what should be the for loop code for the buttons?

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

if Statement Help Increment Value 2 Answers

(if statement) is acting weird 1 Answer

TBG,If,While 1 Answer

Why is this if-statement returning true? 1 Answer

Check if gravity is inverted 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