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 drodrii · Jul 22, 2014 at 03:57 AM · guibuttonongui

Debug.Log - Pressing Button readings.

Hello everyone.

I need desperate help on what's going on, I've been here for like an hour looking at code and still have no idea what's wrong.

Before I ask my question, here's the code of a not-so-simple(due to functionality) button layout.

 void OnGUI () {
 
 CreateDPAD();
 SetIdleness();
 }

Create DPAD states the obvious. SetIdleness checks if any button is being pressed.

 private void CreateDPAD(){
 
 
         CreateRightButton();
         CreateLeftButton();
         CreateUpButton();
         CreateDownButton();
 
     }



 private void CreateUpButton(){
         _upButton = UpButtonClicked ();
         if (_upButton)
         {
             //Animation code, irrelevant to the problem. :D
             
         }
 
 
     }


 private bool UpButtonClicked(){
 
         //upClicked = true;
         if(GUI.RepeatButton(new Rect(Screen.width - (BUTTON_WIDTH * 2) - 10,Screen.height - (BUTTON_HEIGHT * 3),50,50),"", "Dpad_ArrowU")){
             UpActive = true;
             return true;
         } else {
             UpActive = false;
             return false;
         }
     }

Here's where my debug statements are.

 private void SetIdleness(){
 
         //Debug.Log ("SettingIdleness");
         if(DownActive || UpActive || LeftActive || RightActive){
             Debug.Log ("A Button is Active!");
         } else if(!DownActive && !UpActive && !LeftActive && !RightActive){
             Debug.Log ("No Button Active");
         }
 
 
     }


Now, here's the wierd part.

This function checks if Im pressing any buttons. If no button is pressed Debug("No active Buttons") else ("Active Button"); On my dbg WHILE any button is pressed I get this:

  • 1st Line: Active Button..

  • 2nd Line: No activeButtons...

Why is this happening???

Thanks for your time and help, I've been looking at code for an hour and I don't know whats going on....

Comment
Add comment · Show 5
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 Kiwasi · Jul 22, 2014 at 04:17 AM 0
Share

OnGUI is often called multiple times per frame for various reasons. This could be related.

avatar image drodrii · Jul 22, 2014 at 04:29 AM 0
Share

@Bored$$anonymous$$ormon

Even though the button was never let go?(Unclicked..)

avatar image Kiwasi · Jul 22, 2014 at 04:39 AM 0
Share

Yes. There are always multiple passes.

Where exactly are you putting your debug.log statements?

avatar image drodrii · Jul 22, 2014 at 02:17 PM 0
Share

@Bored$$anonymous$$ormon

The log statements are inside SetIdleness function, inside the OnGUI, AFTER Create DPAD.( Just like in the code I provided..)

avatar image drodrii · Jul 22, 2014 at 02:18 PM 0
Share

@Bored$$anonymous$$ormon

I even added UpActive because _upButton, which is basically a boolean that equals to what the button returns(if is pressed true, if not, false)...I added UpActive to try and see if that was the problem..It wasnt :(

2 Replies

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

Answer by drodrii · Jul 22, 2014 at 06:39 PM

The problem is that it gets executed several times. You can check it e.g. by also showing Event.current, which will tell you that first the layout is handled and then the actual repainting takes place. Only during the repainting, you are going to get the correct answer. If you show the value e.g. in Update or any other place than OnGUI, you are going to get the correct result. The problem is that you are using and else for the GUI.RepeatButton. This does not work with an immediate gui solution. This answer was given by @Dantus and it is the solution.

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 perrygarg · Jul 22, 2014 at 06:23 AM

example image

According to me in your console window, 'Collapse' button is pressed, due to which same kind of messages are being grouped together as i show in example image above(highlighted with yellow highlighter)..just disable it and try again. I think your problem should b solved by this. Gud luck :)


capture.jpg (13.4 kB)
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 drodrii · Jul 22, 2014 at 02:15 PM 0
Share

@perrygarg Nope, Collapse isn't clicked. :(

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

24 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 avatar image avatar image avatar image avatar image

Related Questions

Making texture cover whole button 1 Answer

GUI.DrawTexture on GUI.Button press 1 Answer

[FIXED] Why is my GUI.Button always pressed? 0 Answers

iPhone Touch Screen? 2 Answers

How to give animation to the on gui button? 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