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 dglendening · Aug 28, 2014 at 09:44 PM · javascriptguicolliderjava

How to display GUI in sequence in trigger

Here is what I'm attempting to do, in gameplay description:

Player moves into trigger collider.

Player presses a button (Space) --> A GUI is displayed.

Player presses button again --> Second GUI is displayed.

Player presses button again --> Third GUI is displayed.

Player exits trigger collider --> GUI disabled.

So far, I've been able to cobble together a java code that is really very close to doing what I would like it to do. However, I can't figure out, yet, how to allow the player to press the same button (ie Space) in order to flip through the GUI "pages." This is, probably, because I'm using the function Update code. I'm very new at this, so hopefully this isn't a painfully obvious question.

Here's my code as it exists now:

 #pragma strict
 
     var Texture1 : GUITexture;
       var Texture2 : GUITexture;
     var Texture3 : GUITexture;
 
     function OnTriggerStay()
     {
     if(Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = true;
     Texture2.enabled = false;
     Texture3.enabled = false;
         }
     }
     
     function Update()
     {
     if(Texture1.enabled == true)
     {
     if(Input.GetKeyDown( KeyCode.L ))
     {
     Texture1.enabled = false;
     Texture2.enabled = true;
     Texture3.enabled = false;
     }
 }
     
     if(Texture2.enabled == true)
     {
     if(Input.GetKeyDown( KeyCode.K ))
     {
     Texture1.enabled = false;
     Texture2.enabled = false;
     Texture3.enabled = true;
     }
     }
     }
      
     function OnTriggerExit(){
      
      Texture1.enabled = false;
      Texture2.enabled = false;
      Texture3.enabled = false;
      
     }


Thanks, any advice is greatly appreciated!

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 dglendening · Aug 29, 2014 at 09:13 AM 0
Share

Thanks for your suggestion --

I'm not sure it's solving the problem, however -- with the break command, the inspector pops up with a notification that there is no loop in place to break from -- perhaps it needs a loop to cycle the textureNumber? not sure -- if I remove "break" it will successfully bring up the first GUI, but no others.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by UniqueDragutin · Aug 29, 2014 at 03:42 AM

Check once if player press space then check which texture is enabled(first check texture 1 then if that texture is not enabled check second texture and so on)..

 if(Input.GetKeyDown(Keycode.Space)){
 if(Texture1.enabled){
 }
 else if(Texture2.enabled){
 }    
 }

Hope I helped.

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 Maui-M · Aug 28, 2014 at 10:02 PM

You should be able to get what your looking for with the following code. You could also look into doing it with List as well.

 var Texture1 : GUITexture;
 var Texture2 : GUITexture;
 var Texture3 : GUITexture;
 var textureNumber : int = 1;
 
 function OnTriggerStay()
 {
     if(Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = false;
         Texture2.enabled = false;
         Texture3.enabled = false;
         
         if(textureNumber == 1)
             Texture1.enabled = true;
         else if(textureNumber == 2)
             Texture2.enabled = true;
         else if(textureNumber == 3)
             Texture3.enabled = true;
         else
             break;
         
         textureNumber++;
     }
 }
 
 function OnTriggerExit(){
      textureNumber = 1;
      Texture1.enabled = false;
      Texture2.enabled = false;
      Texture3.enabled = false;
 }
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 dglendening · Sep 17, 2014 at 04:51 PM 0
Share

Thanks for this -- I was feeling like I had figured out a different solution, as I posted below -- my solution hasnt been very reliable though, and has been calling up GUIs out of sequence, so I wanted to try your script -- I'm running into this error though: "No enclosing loop out of which to break or continue."

Any thoughts?

Thanks much

avatar image
0

Answer by dglendening · Aug 29, 2014 at 12:44 AM

Nevermind team, I think I figured it out. Here's what I came up with:

     var Texture1 : GUITexture;
       var Texture2 : GUITexture;
     var Texture3 : GUITexture;
 
     function OnTriggerStay()
     {
     if(Texture1.enabled == false && Texture2.enabled == false && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = true;
     Texture2.enabled = false;
     Texture3.enabled = false;
         }
     
     else if(Texture1.enabled == true && Texture2.enabled == false && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = false;
     Texture2.enabled = true;
     Texture3.enabled = false;
     }
         
     else if(Texture1.enabled == false && Texture2.enabled == true && Texture3.enabled == false && Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = false;
     Texture2.enabled = false;
     Texture3.enabled = true;
     }
     
     else if(Texture1.enabled == false && Texture2.enabled == false && Texture3.enabled == true && Input.GetKeyDown( KeyCode.Space ))
     {
         Texture1.enabled = false;
     Texture2.enabled = false;
     Texture3.enabled = false;
     }
     
     }
     
      
 function OnTriggerExit(){
      
 Texture1.enabled = false;
 Texture2.enabled = false;
 Texture3.enabled = false;
      
     }
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 dglendening · Sep 17, 2014 at 04:52 PM 0
Share

This isn't totally working, though -- for some reason, when testing the gameplay, GUIs get called up out of sequence. Not sure what the deal is.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is it the same javascript 1 Answer

Script doesn't find other script 0 Answers

GUI animated menus 2 Answers

How to disable "GameObject" Then Enable After Animation. 1 Answer

oescape script name? 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