better way to handle gamepad support

if (Input.GetKey(KeyCode.W))
{

         if (canjump)
         { 
         rb2d.velocity = new Vector2(rb2d.velocity.x, jump);
         jumpsleft--;
         }  
            
            
        }
         if (Input.GetKey(KeyCode.JoystickButton0)) 
        {
        
         if (canjump)
         { 
         rb2d.velocity = new Vector2(rb2d.velocity.x, jump);
         jumpsleft--;
         }  
            
            
        }

Unity has a relatively new input system available in the Package Manager. Brackey’s also has a tutorial video from 2019 featuring a very basic implementation of this input system which harnesses event subscription to fire events on button press.

With this input system, you’d subscribe to an event by passing a method to the event delegate in Awake() (and unsubscribing in Destroy() so you don’t incur memory leak) and then when the button is pressed, an event is raised and the method passed will fire. I would highly recommend watching the linked video, it does a pretty nice job of laying out the format and the basics.