Unity invert < and >?

Hello, I’m not very good in Unity, but I want to modify and connect a game with ChatGPT, and when I made an if (), I remark something, confused.

In my code :

if (munitions < 1)
{
    Debug.Log("Pas assez de munitions pour tirer!");
    return;
}

I would say : "if munition != 0 other less than 0", with

if (munitions > -1) {}

That don’t work, but with munitions < 1 that work.

(I am french, and I don’t use google translate, so sorry if my English is bad)

1 Answer

1

Your description is really confusing. Why would you use such weird limits? Your first condition

if (munitions < 1)

is the same as

if (munitions <= 0)

So the condition is true when munitions is 0 or less than 0

Your second condition

if (munitions > -1)

is the same as

if (munitions >= 0)

So this condition is true when munitions is 0 or greater than 0

I’m not sure what you want to do, but those two conditions are not the inverse of each other since both include the number 0

Please mention, that this is only true for integer-type variables (long, int, etc.).

–

Sorry for the latency of my response, I preferred to put > 1 because I had already noticed the "problem", and I told myself that that was it, conclusion: no. However, what I mean is that e.x.: JavaScript: if (life < 1) {} C#: if (life > 1) {} In my code it does the same thing?!

–