if statement keeps recurring, i only want it to happen once.

My game has a cash value that determines what a player can buy or not. If their cash is beyond a certain point, visual upgrades are unlocked.

I have done this by changing the alpha of images from 0f to 1f when the cash of the player reaches a specific number. The problem is, once a player has bought something and the cash is subtracted, the cash is suddenly less than the threshold and the image’s alpha resets to 0.

How do I make it so that once the cash amount needed is reached, the image’s alpha can never be changed again, unless instructed so by a different if statement?
p.s: for the upgrades, no cash is subtracted.

if(newCarAlpha.a != 1.0f)
{
//it hasn’t changed
newCarAlpha.a = 0.0f;
}

The above will check if the newCarAlpha has already been set to 1 and if not it will be set to 0.

Keep a boolean variable for it.

If money is less than a specific amount keep the boolean false, when your money reaches specific amount set it to true.

Add a if condition stating if your money has reached its specified limit then your alpha will not change.