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 David_2 · Oct 20, 2014 at 09:30 AM · debug

my button cant do anything but write a debug log

I'm trying to make this button subtract one float from another (dropsCount = dropsCount - dropsCost) but when I do that it will still write the debug log but the float is left unchanged I'm new to this so any help would be awesome and if you could explain what I did wrong it would be even better thanks!

edit: sorry, will put the bit in where I want it to work and yeah the debug runs just fine, its my way of testing the computer actually knows when the button should work.

 void OnGUI(){
     if (menuOpen == true) {        
         if (GUI.Button (new Rect ( 20, 70, 220, 25), "button TXT")){
             if ( floatCount >= floatCost){
                 Debug.Log("this works and appears");
                                     // but this doesn't change dropsCount at all
                                     dropsCount = dropsCount - dropsCost;
             }
         }
     }
 }
Comment
Add comment · Show 9
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 HarshadK · Oct 20, 2014 at 09:35 AM 0
Share

Couldn't find float = float - floatSubtract in your code above. Plus Debug.Log is gonna execute when the if condition stands true.

avatar image Kiwasi · Oct 20, 2014 at 09:35 AM 0
Share

Want to post the code that doesn't work? I see nothing wrong here.

avatar image Wisearn · Oct 20, 2014 at 09:41 AM 0
Share

With your current code, when you see the debug.log the "dropsCount" is going to subtract "dropsCost" from itself.

$$anonymous$$aybe you also need to do floatCount -= floatCost; ?

avatar image Bunny83 · Oct 20, 2014 at 09:51 AM 1
Share

@Wisearn: using "-=" is just the short form of what the OP does. It won't change anything on what the code does.

@$$anonymous$$_2: Like other said, there's nothing wrong with this small piece of code. Where are your two variables defined and what values do they have? Also where, when and how do you check if the value has changed or not?

You should change your Debug.Log to:

     Debug.Log("Subtract " + dropsCost + " from " + dropsCount );

$$anonymous$$aybe your dropsCost is 0?

ps: What's actually "floatCount" and "floatCost"? Have you renamed them, partially? Please post your actual code or we can't really help you.

avatar image David_2 · Oct 20, 2014 at 09:57 AM 0
Share

Defined in void start I think And yeah not set to 0 Will try that -= dropscost when I'm at pc next When I set a key to do that same function in update it works fine.

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Random Blank Loaded Scene 1 Answer

Debug an occasional freeze 0 Answers

Hey !! i am taking a screenshot in one of my app that shot is saved in (android/data/app/shot) by default can i change its path directly to gallary? if yes thn how ? 0 Answers

Unity 2017 frame rate capped? 2 Answers

Can I see debug log(ex:printf) from C++ dll in Unity? 0 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