How to subtract from an int

Sticks++ adds +1 each time , which is what I want but sticks-- doesn’t -1 each time , why does this happen?For example if int = 50 it subtracts 6 and keep on going . I need it to -1 from the int value each time.

7535288--930545--Untitled.png

use sticks -= 1

why isnt – not -1 thou

I’ve used -= 1 already , I get the same result . When Int = 50 and Q is pressed once , it subtracts 26 for some reason . I’m aware it won’t stop at 0 but I still don’t understand why it doesnt subtract 1 each time.

try:

void AddSticks() {
    Debug.Log("before adding, sticks was: " + sticks);
    sticks++;
    Debug.Log("after adding, sticks was: " + sticks);    
}

void RemoveSticks() {
    Debug.Log("before removing, sticks was: " + sticks);
    sticks--;
    Debug.Log("after removing, sticks was: " + sticks);   
}

Also, please post your code in Code Tags rather than a screenshot, so we can copy-paste it when helping.

1 Like

Is it a fixed number that gets removed? or random?
Maybe u are using onbutton/key instead of onbutton/key down?

1 Like

Thank you for your input.
I can confirm Onbutton/Key was the issue

Thanks for the input and advice , I’ll keep that in mind next time . The issue has been resolved

Thanks for this btw, I had a issue with my health bar script, this resolved it.

1 Like