GetKeyDown(KeyCode.Space) not working!?

Hey guys, as beginner in scripting, I am trying to make movements for my “character”. Everytime I press spacebar or tap on my screen of my phone, it does not work in the simulator. My goal is to make my “character” go down which means that the velocity needs to be negative. I have set the gravity of the object a positive number. What did I do wrong?


bool didfly = false;

void update(){

	 if(Input.GetKeyDown(KeyCode.Space) ||  Input.GetMouseButtonDown(0) ) {
		didfly = true;
		   }
		}

Thanks in advance!

void update()
Should most certainly read:

void Update()

What exactly is not working with the code you posted?
To test out if it works just change it to:

void update(){
 
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
    Debug.Log("test"); //this
}

But I suspect what you are asking is how to make your “character” go down, which I suppose you have a code made for it already, because “didfly” bool just ain’t gonna cut it. Does your going-down code works or not? If your question on how to make your character go down, then you can just have the rigidbody on your character be affected by gravity, and just make him be Kinematic whenever didfly is false:

//add this to the update void with the rest you've got
if(!didfly) { //if didfly is false, then make char Kinematic
    rigidbody.isKinematic = true;
} else {
    rigidbody.isKinematic = false;
}

That’s about it.

Try
if(Input.GetKeyDown(“space”)||Input.GetMouseButtonDown(0) ) {
didfly = true;
}
}