Change player gravity by pressing a key?

Hi!

I’m trying to create a isometric prototype project, where the gravity of the player object changes with a press of a key.

The problem is, I have nothing more to offer than this question, how should I start, or where should I start to solve this problem myself?

Thanks in advance! :^)

PS. If you’re kindhearted, and you’re willing to provide me a sample code, please do write it in C#

If you want to chang gravity. These are gravity setting in

Edit > Project settings > Physics

But if you want to change via script. You can do this.

public bool gravitySwitch;
void Update()
{
    if (Input.GetKeyDown(Keycode.G) //Detect if player press G key. You can learn more at Unity Input. If you want
    {
        gravitySwitch = !gravitySwitch;
        if (gravitySwitch)
        {
             Physics.gravity = new Vector3(0,9.81,0); //Invert
        }
        else If (!gravitySwitch)
         {
              Physics.gravity = new Vector3(0,-9.81,0); //Default unity
         }
    }
}

If you want more complex code. For whatever reason. Here

public bool gravitySwitch;
public void Update()
{
    if (Input.GetKeyDown(Keycode.G)
    {
         gravitySwitch = !gravitySwitch;
         Physics.gravity = !gravitySwitch ? new Vector3(0,9.81) : new Vector3(0.9.81,0);
    }
}

Script API documentation: Physics & Input