• 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 WesterlyCarrot9 · Dec 12, 2013 at 01:11 PM · c#javascriptguibuttonkey

Key for GUI.Button

I'm so frustrated so i hope you good people in the community can help :P I want to make my two GUI.Buttons from the code below to activate with keys and i've done it before in simpler scripts but it just won't work here! Any help? Thanks!

 var Pressed : boolean = false;
 var charPressed : boolean = false;
 
 var guiRatio : float;
 var sWidth : float;
 var GUIsF : Vector3;
 
 var cube : GameObject;
 var check : boolean = false;
 
 function Awake(){
     sWidth = Screen.width;
     guiRatio = sWidth / 1440;
     GUIsF = new Vector3(guiRatio,guiRatio,1);
 }
 
 function Update(){
     if(cube == null){
         check = true;
     }    
 }                
 
 function OnGUI(){
         if(check){
                 GUI.matrix = Matrix4x4.TRS(new Vector3(Screen.width - 100*GUIsF.x,Screen.height - 60*GUIsF.y,0),Quaternion.identity,GUIsF);
                 if(GUI.Button(new Rect(-20,-20,100,60),"Deer")){
                     gameObject.GetComponent(CharacterMotor).jumping.baseHeight = gameObject.GetComponent(CharacterMotor).jumping.baseHeight + 3;
                     Pressed = true;
                         if(gameObject.GetComponent(CharacterMotor).jumping.baseHeight >= 4){
                             gameObject.GetComponent(CharacterMotor).jumping.baseHeight = 4;
                         }
                     }
                 }                                                                                    
                 if(Pressed){
                     GUI.matrix = Matrix4x4.TRS(new Vector3(Screen.width - 100*GUIsF.x,Screen.height - 60*GUIsF.y,0),Quaternion.identity,GUIsF);
                     if(GUI.Button(new Rect(-20,-100,100,60),"Stop")){
                         gameObject.GetComponent(CharacterMotor).jumping.baseHeight = 1;
                         Pressed = !Pressed;
                     }
                 }
             }    

     
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 KellyThomas · Dec 12, 2013 at 01:41 PM 0
Share

What is happening when you run this code?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by premier · Dec 12, 2013 at 01:44 PM

On GUI.Button you have option to set a tooltip (good for hover effects) or set ID parameter! You can use ID for any button you have.

In my scripts every time i click in gui.button i send a message for all scripts who extends my other script, like this:

 Events.ToList().ForEach(evt => evt.OnClickUIButton(ID));

Then in other script i have:

 public void OnClickUIButton(string ID) {
     switch(ID) {
         case "PlayGame":
             // do same action
             break;
     }
 }
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
-2

Answer by WesterlyCarrot9 · Dec 12, 2013 at 01:48 PM

Nevermind guys i just figured out what need to be done :P Thanks for your replies anyway :P

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 iwaldrop · Dec 12, 2013 at 05:02 PM 0
Share

You really should have accepted the answer by premier, or at least detailed your solution. This is a community site for archiving answers.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 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

Related Questions

Assign a hotkey to a GUI button? 3 Answers

GUI Button Disappearing 1 Answer

I have doubt please help me 2 Answers

Multiple Cars not working 1 Answer

Javascript GUI.Button help, Error BCE0077 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