gravity change via controls(help) 2d,Anyone know how to fix this gravity thing

anyone know how to fix this 2d gravity controller button thingy for players
,\I’m trying to make gravity controllable anyone know how to fix my errors I just started c# so I’m bad at it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gravitycontroller : MonoBehaviour
{

    public Vector2 gravity;
    public float gravForce = 9.81f;
    public int gravPull;
    void Start()
    { 
        gravity.x = 0;
        gravity.y = -9;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.W)) 
        {
           gravity.y = 1;
        }
        else if (Input.GetKey(KeyCode.S)) 
        {
            gravity.y=-1;
        }
        else if (Input.GetKey(KeyCode.A)) 
        {
           gravity.x= 1;
        }
        else if (Input.GetKey(KeyCode.D)) 
        {
            gravity.x= -1;
        }
        else if (Input.GetKey(KeyCode.Z))
        {
            gravity.y=0;
        }
    }
}

What exactly is wrong with your code? You haven’t written what doesn’t work.

If you want to affect gravity for all rigidbody2d objects in-game, you have to change gravity in Physics2D object. Refer to unity documentation: Unity - Scripting API: Physics2D.gravity