Boolean True/False

I have a boolean value and an if for if its equal to true or false but how couldi make a switch for it if you press a button(i know how to start something if a button is pressed) but is there an actualy code that switches if back inforth without using a lot of if statments? I have this code too i tried and it does not seem to work?
Edit: Wrong code piece :slight_smile:

I think you need to stop asking these kinds of questions over and over again on this forum, you are not asking people to help you, in previous threads you just want them to give you the code so you can copy and paste it in.

Actualy im not would you like to see my code???That i have been working on? And that ones that i have asked i usualy asked “How to do it” not the actualy code just how i would go about doing it. And before doing it i have looked up most of these things extensively.

you use a switch for a boolean o.o?

try if else .

and btw you are comparing bool with a string

my code i used i have an if else to do if its true and if its false but i want when i pressed a button to toggle on off but i cant figure out how to toggle(im not using gui)

toggle

walk = (walk == true) ? false : true;

What do you mean by toggle?
You press and release button and it toggles once?
You press an hold btn it toggles infinitly?

But over all…
If(on == true)
On = false;
Else if (on == false)
On = true;

if(Input.GetKeyDown(KeyCode.A))
{
	if(walk)
	walk = false;
	else true;
}

thanks all.

I’m surprised nobody posted this… Shame on all of you for not knowing :stuck_out_tongue:

walk = !walk;
7 Likes

lol thanks Daniel !