Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Technosasquach · Sep 25, 2014 at 11:21 AM · bugvariable

Weird Game Breaking Variable Bug

I'm been programming a quiz type game with the new 4.6 UI system. And i have an answer variable that ranges 1 - 4 for the toggle group. Currently if i try to build with a change to this variable for testing, it dose not update in unity, IE: if it was answer 2 that was correct it would remain correct regardless of the code alterations. I tracked it down to void start() when it has been changed by then back to the original number. Though during the running of the game the variable can be changed.

At first i thought it was a simple sync bug with Visual Studio, but even to the extent of restarting the computer its the same (i did re sync and restart unity and VS). It would only update if i changed the name and then number of the variable. Also to be more painful it only occurs with this particular variable.

I was wondering if anyone has had the problem before, and if anyone knew how to fix it.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class UIManager : MonoBehaviour {
 
     private int curr_canvas; //Main: 0, Esc: 1, Settings: 3, Help: 4, Teaching: 5, Quizzing: 6
     public GameObject[] canvas;
 
     public string[] Quiz = { "Question 1", "How is the weather today?", "Cloudy", "Sunny", "Rainy", "Snowy" };
     public GameObject[] quiz_canvas; //Title, Question, Q1, Q2, Q3, Q4
     public GameObject[] toggle;
     public int Anwser = 1;
     public bool Q_1;
     public bool Q_2;
     public bool Q_3;
     public bool Q_4;
     public bool Correct;
 
     void Start () {
         curr_canvas = 0;
         SetCanvas(0);
     }
     
     void Update () {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             Debug.Log("SettingCanvas");
             switch (curr_canvas)
             {
                 case 0:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(1);
                     break;
                 case 1:
                     Debug.Log("SetCanvas(0)");
                     SetCanvas(0);
                     break;
                 case 2:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(1);
                     break;
                 case 3:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(1);
                     break;
                 case 4:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(1);
                     break;
                 case 5:
                     Debug.Log("SetCanvas(0)");
                     SetCanvas(1);
                     break;
                 case 6:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 7:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 8:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 9:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 10:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 11:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 12:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 case 13:
                     Debug.Log("SetCanvas(1)");
                     SetCanvas(0);
                     break;
                 default:
                     Debug.Log("SetCanvas(0)");
                     SetCanvas(1);
                     break;
             }
         }
         if (Input.GetKeyDown(KeyCode.P))
         {
             SetCanvas(4);
             SetQuiz();
         }
         if (Input.GetKeyDown(KeyCode.O))
         {
             SetCanvas(5);
         }
     }
 
     public void SetCanvas(int showCanvas)
     {
         curr_canvas = showCanvas;
         int i = 0;
         do
         {
             if (i == curr_canvas)
             {
                 canvas[i].SetActive(true);
             }
             else
             {
                 canvas[i].SetActive(false);
             }
             i++;
         } while (i < canvas.Length);
     }
 
     public void SetQuiz()
     {
         quiz_canvas[0].GetComponent<Text>().text = Quiz[0]; //Title
         quiz_canvas[1].GetComponent<Text>().text = Quiz[1]; //Text Area
         quiz_canvas[2].GetComponent<Text>().text = Quiz[2]; //Q1
         quiz_canvas[3].GetComponent<Text>().text = Quiz[3]; //Q2
         quiz_canvas[4].GetComponent<Text>().text = Quiz[4]; //Q3
         quiz_canvas[5].GetComponent<Text>().text = Quiz[5]; //Q4
     }
 
     public void CheckQuiz()
     {
         Debug.Log("Anwser Before : " + Anwser);
         SetAnwser(Anwser);
 
         if (toggle[0].GetComponent<Toggle>().isOn == true && Q_1)
         {
             Correct = true;
             Debug.Log("Correct: True 1");
         }
         else if (toggle[1].GetComponent<Toggle>().isOn == true && Q_2)
         {
             Correct = true;
             Debug.Log("Correct: True 2");
         }
         else if (toggle[2].GetComponent<Toggle>().isOn == true && Q_3)
         {
             Correct = true;
             Debug.Log("Correct: True 3");
         }
         else if (toggle[3].GetComponent<Toggle>().isOn == true && Q_4)
         {
             Correct = true;
             Debug.Log("Correct: True 4");
         }
         else
         {
             Correct = false;
             Debug.Log("Correct: False");
         }
         alpha++;
     }
 
     public void SetAnwser(int anwser)
     {
         Debug.Log("Anwser Int: " + anwser);
         if (anwser == 1)
         {
             Q_1 = true;
             Q_2 = false;
             Q_3 = false;
             Q_4 = false;
             Debug.Log("Anwser 1");
         }
         if (anwser == 2)
         {
             Q_1 = false;
             Q_2 = true;
             Q_3 = false;
             Q_4 = false;
             Debug.Log("Anwser 2");
         }
         if (anwser == 3)
         {
             Q_1 = false;
             Q_2 = false;
             Q_3 = true;
             Q_4 = false;
             Debug.Log("Anwser 3");
         }
         if (anwser == 4)
         {
             Q_1 = false;
             Q_2 = false;
             Q_3 = false;
             Q_4 = true;
             Debug.Log("Anwser 4");
         }
     }
 }


I also apologize for some of the shoddiness with the code but it works except for the variable. The variable in question is 'anwser'.

Thanks

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Changing variable values not having any effect 2 Answers

Why isn't the variable being assigned? 1 Answer

Variable changes to a negative number somehow 1 Answer

[C#] Assets/BreakObject.cs(20,62): error CS0165: Use of unassigned local variable `broken' 1 Answer

Variable value not changhing 3 Answers


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