Erro: not all code paths return a value

hey, I’m new to unity and C#. I’m trying to practice on coding and I got this problem:

the console keeps saying not all code paths return a value!

and simply my code is:

   public float InputGetAxis(string axis ){
		float v = Input.GetAxis(axis);
		if(Mathf.Abs(v)>0.05f)return v;
		if(axis == "Horizontal")return axisH;
	}

so anyone could help~ thanks

Your function InputGetAxis will not always return a value. You need to have a return statement outside of your if statements so that if those conditions are not met it will return a value.

public float InputGetAxis(string axis)
{
  float v = Input.GetAxis(axis);
  if(Mathf.Abs(v) > 0.05f) 
  {
     return v;
  }
  if(axis == "Horizontal") 
  { 
     return axisH;
  }
  return 0.0f;
}

First thing about programming is learning to read the error messages and understanding methods that return values, they have to return a value of the applicable type.

The function above should get you working but I’ve no idea if it will give you the behaviour you expect as you have not made it clear what you are trying to do.