Gravity troubles !

Hi everyone! I am making a 2D endless runner , the idea is : player must jump from the floor to the ceiling or from the ceiling to the floor to avoid obstacles .


To do so I want to change its gravity every time when I want to jump . I am using this code :
And it works ! But not always, sometimes it makes a tiny jump so I need to press the button a few times to make it move to the ceiling. Pls tell me what am I doing wrong ? And why sometimes it can not change the gravity with one press? Thank you a lot !

It will enter in GetMouseButton every frame until the button is pressed, you should use GetMouseButtonDown instead.