Some Input related questions

Yesterday i created some controls for my first game. Practice is the best way to learn so after reading some tutorials i got to work…

after a days work on the controls i have some question i wanted to ask…

  1. Setting speed

So i want to use the vertical axis to control the speed. If a player holds z, the speed must increas untill it reaches a max value. Same for s but than increase untill a min value (for going backwards).

Therefore i used something like that:

function Update()
{
   var changeY : float = Input.GetAxis("Vertical");
   if(changeY > 0)
   {
     currentSpeed += changeY
   }
   if(currentSpeed > maxSpeed)
     currentSpeed = maxSpeed;
   if(currentSpeed < 0)
     currentSpeed = 0;
}

The problem with this is that i can’t seem to find a good balance. When i hold the z to increase my speed, it goes like hell. It doesn’t increase slowly. When i do a print(changeY) inside the if(changeY > 0) i notice it get’s called every frame. So perhaps their is the issue.
This is my second question… How can i control such a thing so it doesn’t get called every frame but instead every 0.5s or so. Or what is common use to control speed in such a way? [/code]

  1. Is theire a onButtonPressed function?

For now i use the update() function to check if their is a specific button pressed:

function Update()
{
   if(Input.GetButtonUp("Fire1")
   {
     doSomething();
   }
}

Is their a function that receives a parameter telling me witch function is pressed. This way i don’t have to do all my checks in the update or is it just the way to go in Unity?

  1. The Input Manager has a sensitivity setting that controls how long it takes an input axis to reach its maximum value.

  2. MonoBehaviour has an OnMouseDown event, but it only fires when the mouse is over a GUI element or a collider. For other cases, you are already using the right technique.