Is there any way to subtract int / float if another int / float subtracted?
Hello, i wonder if there any way to subtract int or float if another int or float subtracted.
Here's an example :
Int_A -= Random.Range(1, 4)
Int_B = // subtract the same int value as Int_A
thx
Im really shock to see 700+ users following my question in under 5 $$anonymous$$utes! i guess everyone was finding this useful
Answer by Bunny83 · Aug 08, 2020 at 10:31 AM
The way your title and your description is worded it's actually really hard to tell what you're actually asking. The title suggests that you want some kind of conditional action. Your code in your description looks like you just want to change two variables at the same time. Though I'm not entirely sure what
subtract the same int value as Int_A
exactly means, however I guess you mean something like this:
int rnd = Random.Range(1, 4);
Int_A -= rnd;
Int_B -= rnd;
Though If you need / want to do this in several places you might want to consider writing a method for that:
void ApplyChange(int aChange)
{
Int_A -= aChange;
Int_B -= aChange;
}
That way you can just use
ApplyChange(Random.Range(1, 4));
to subtract either 1, 2 or 3 from both variables.
I am so sorry if my title is hard to tell, but what i meant is by changing two variables at the same time and it looks like u got the answer and thx so much.