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
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
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.