- Home /
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;
}
}
}
}
Couldn't find float = float - floatSubtract in your code above. Plus Debug.Log is gonna execute when the if condition stands true.
Want to post the code that doesn't work? I see nothing wrong here.
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; ?
@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.
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.
Your answer
Follow this Question
Related Questions
Random Blank Loaded Scene 1 Answer
Debug an occasional freeze 0 Answers
Unity 2017 frame rate capped? 2 Answers
Can I see debug log(ex:printf) from C++ dll in Unity? 0 Answers