My first Script in unity...

For my first script in unity i tired to make a very simple flying game.(Yes i know it is missing pitch and roll)
The first major issue is that when i try to yaw left it only increments by one degree every time i press the button, despite me having the yaw var at 5. Also how would i script it so you can just hold the button down? (with loops?)
The proboly are a million other things wrong with my script but oh well… thanks in advance.

var speedInput = 0;
var yaw = 10f;
function Start () {
}

function Update () {
	if(Input.GetButtonDown("SpeedUp")){ 
		speedInput++;
	}
	if(Input.GetButtonDown("SpeedDown")){
		speedInput--;
	}
	transform.Translate(Vector3.forward * speedInput * Time.deltaTime);
	Debug.Log(speedInput * Time.deltaTime);   //This paragraph is for speed


	
	if(Input.GetButtonDown("YawLeft")){ 
	transform.Rotate(Vector3(0, -yaw * Time.deltaTime, 0));
	}
	if(Input.GetButtonDown("YawRight")){
	transform.Rotate(Vector3(0, yaw * Time.deltaTime, 0));  //this "paragraph is for yaw"
	}
}

To just hold the button down, use Input.GetButton() instead of Input.GetButtonDown(). As for your increment problem, Javascript variables are public by default. So after this script is attached, changes in initialization of public variables will be ignored. You can solve this problem by:

  • Putting ‘private’ in front of the variables to make them private.
  • Changing the value in the inspector
  • Use the dropdown marked by a gear in the upper right corner of the script in the inspector to reset the variables to the values in the script.