Other way to write a code
for some reason when I put this code in the update function it will not work is there a other way to write this code?
if(canIncrease && notFullHealth == false && Input.GetKeyDown(KeyCode.G))
{
Atext();
}
I'd say, first of all, do a Debug.Log into the console, for the canIncrease
, notFullHealth
and Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.G)
variables and see if they are all right.
Put this before the if statement:
Debug.Log("canIncrease: " + canIncrease + " | notFullHealth: " + notFullHealth + " | Input: " + Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.G))
And then look in the console, if you ever get
"canIncrease: true | notFullHealth: false | Input: true"
Yes I get them except for the input: true its stays at false.
never $$anonymous$$d i fixed the problem but thanks anyway
are you sure because every thing looks fine, even if I prefer it better with brackets just check that its void Update() not void update()
one improvement:
notFullHealth == false
==
!notFullHealth
When reading the code I would prefer the first option. The second option would be read as a double negative "not not Full Health" vs "not Full health equals false".
thats correct. But you usually name your bool after the true state, and then you'd use the exclamation mark
Your answer
Follow this Question
Related Questions
trouble switching between booleans 2 Answers
Unity Update is ignoring the GetKey part of my statement!? 2 Answers
How to make a gameObject appear when I press spacebar down? 1 Answer
can you set boolean values using the input.getkeydown(keycode.(key)) 1 Answer
How do you wait for key press before a game starts? 2 Answers