Listener of inputs? Does it exists?

Hi, i’m reading a book called Unity Game Development Essentials, and for interceptate input events it uses:

void Update () {

		if(Input.GetButtonDown("Fire1")){
			audio.PlayOneShot(throwSound);
		}
	
	}

But my question is: aint better to use a specific listener instead to perform “if” statement for every update?
Something like

void OnFire1Press(){
//some code
}

or else

void OnButtonPress ( Input btn)
   {
     if (btn=="Fire1")
    {
     //some code
    }
}

does it exists?

No, there is no input->methodcall system built into Unity. You could write one:

void Update()
{
  if(Input.GetButtonDown("Fire1")) SendMessage("OnFire1Press");
  if(Input.GetButtonDown("Fire2")) SendMessage("OnFire2Press");
  /* ... etc ... */
}