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 adrennalinpro · May 19, 2014 at 07:40 PM · guihideshow

Confusing Logic (Just need some help with what goes where)

So my game has a tutorial... when you press any key at the start, the first Welcome GUI is replaced by your first instruction GUI, telling you what to do. Once you click the button "Continue", that GUI goes away and the game goes into action. Once you pick up an ammo box, as instructed, another GUI comes up and asks you to reload your ammo. Eventually, I will make it ask you to shoot the target, and then walk through the now open gate. Everything works, I just have my logic wrong, I think.

As many know, coding requires the ability to think logically and critically when making if() statements. I'm usually okay with this, but right now I'm stumped as to where my logic went wrong.

My problem starts when I hit the "Continue" Button. First of all, it does not disappear as it should... that may be a syntax problem, but I'm not sure. Once you click "Continue", both the button and the GUITexture it hovers over should disappear until the player picks up some ammo. Then, it should bring up another GUI. All of this happens, but the GUI button and Texture does not disappear when the button is clicked. You can even step onto the ammo box, picking it up, and cause the next GUI to come up... but the other one is still there and it totally messes up what the player should see. I've tried using booleans, as you might notice the vast amount of them in the variables section, to cause the GUI to disappear when the player starts up, but to no avail.

I apologize deeply for the mess of code in this script... I would very much appreciate any help that I can get with this.

(P.S. I noticed that on these forums people answer specifically to what you ask, offering no further information after that. I would be grateful if you include any errors that you might see in this script, potentially causing this glitch. If it's syntax or logic, or even typo, please.. don't hesitate to point it out. Thanks!)

My code:

     #pragma strict
     
     var StartG : GUITexture; //This is the background texture that the text lays over. 
 //It is used multiple times throughout the script for different messages to the player.
     var StartG2 : GUITexture; //This is the "Welcome" message via a texture. 
 //It thanks the player for playing.. etc.
     var TutG : GUITexture; //This is the first instruction given to the player. 
 //It just says to grab some ammo.
     var TutG2 : GUITexture; //This is the second bit of instruction to the player.
 // It just tells the player to reload with "R".
     var ExG : GUITexture; //This hasn't been used yet, but it will be the message 
 //telling the player to exit through the now open gate.
     var Char : GameObject; //This is an object used to deactivate/activate the player's gun, 
 //which should not be allowed to be used while the game is "paused" during a GUI message.
     var Aim : GameObject; //This deactivates/activates part 1 of my mouselook script
     var Aim2 : GameObject; //This deactivates/activates part 2 of my mouselook script
     var Welcome : boolean; //This is used to make sure the first GUI doesn't over-power
 //the other GUIs in the future, because the key input might cause issues and glitches.
     var Tutorial : boolean = false; //This is the same as the first, though I do not
 //remember where I used it.. perhaps I should look into this?
     var ThatObj : GameObject; //This is the object that holds the script that is called to
 //determine whether or not the player has stepped on the "AmmoBox" in question.
     var Active : GameObject; //Just experimental: I was trying to see if I could make
 //this object inactive when a GUI was deactivated, and in result activating another GUI.
     var TutButton1 : boolean; //The button bool that you see in the first Info GUI.
     var TutButton2 : boolean; //The button bool you see in the second Info GUI.
     var Tut1 : boolean; //The bool used to activate the first info message.
     var Started : boolean; //The bool used to show the welcome msg
     var ThisBool : boolean; //Used to separate a function from an if() statement
     
     function Start () {
     Welcome = true;
     }
     function Update () {
     
             if(TutButton1 == true) {
     
                     Time.timeScale = 1;
                     StartG.enabled = false;
                     Char.active = true;
                     Aim.GetComponent(MouseLook).enabled = true;
                     Aim2.GetComponent(MouseLook).enabled = true;
                     StartG2.enabled = false;
                     Welcome = true;
                     Debug.Log("TutButton1 has been pressed");
                     
         }
             if(TutButton2 == true) {
             
                     Time.timeScale = 1;
                     StartG.enabled = false;
                     TutG.enabled = false;
                     Char.active = true;
                     Aim.GetComponent(MouseLook).enabled = true;
                     Aim2.GetComponent(MouseLook).enabled = true;
                     StartG2.enabled = false;
                     Debug.Log("TutButton2 has been pressed");
                     Destroy(TutG);
                     
         }
             if(Tut1 == true) {
                 TutG.enabled = false;
                 StartG.enabled = true;
                 TutG2.enabled = true;
                 Time.timeScale = 0;
                 Char.active = false;
                 Aim.GetComponent(MouseLook).enabled = false;
                 Aim2.GetComponent(MouseLook).enabled = false;
             }
             if(Started == true) {
                 StartG2.enabled = false;
                 TutG.enabled = true;
                 Welcome = false;
                         if(TutG.enabled == true) {
                         ThisBool = true;
                         }
         }
         
     }
     
     function OnGUI() {
         if(Input.anyKeyDown && Welcome == true) {
             Started = true;
             }
             if(ThisBool == true) {
                 if(GUI.Button (Rect (Screen.width * 0.5, Screen.height * 0.5,80,20), "Continue")) {
                 
                 TutButton1 = true;
     
                 }
                 if(TutButton1 == true) {
                             TutG.enabled = false;
                 }
             
             if(ThatObj.GetComponent(AmmoBox).TutBox == true) {
                     Tut1 = true;
                     }
                 if(Tut1 == true) {
                     if(GUI.Button (Rect (Screen.width * 0.5, Screen.height * 0.5,80,20), "Start")) {
                     
                     TutButton2 = true;
     
                 }
             }
         }
     }
     
 
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

20 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

Related Questions

Multiple Cars not working 1 Answer

show gui when look certain object 2 Answers

How do i make a texbox show and hide 1 Answer

How to Hide the GUI when time.scale = 1 again 1 Answer

Show GUI on collision 2 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