airplane script help

hey i was asking is this script correct for a air plane so far im new to this

code:

var throttleSpeed = 30.0;
var turnleftSpeed = 20.0;
var liftSpeed = 20.0;
var desendSpeed 20.0;
var turnrightSpeed 20.0;

function update()
{
if(Input.GetButtonDown("throttle"))
    transform.Position.x += 15.0;
}
 */

if(GetButton("Lift")) 
{
    transform.position += transform.forward * liftSpeed * Time.deltaTime;
}
if(GetButton("Desend"))
{
    transform.position += transform.forward * desendSpeed * Time.deltaTime;
}
if(GetButton(turnleft)) 
    transform. position += transform.forward * turnleftSpeed * Time.deltaTime

No. If you save this script, Unity will compile it and the console will tell you in bright red letters that this script is wrong because:

  1. The descendSpeed is missing an = sign.
  2. The turnrightSpeed is missing an = sign.
  3. The compiler won't understand the */ in the middle of nowhere.
  4. GetButton takes a string indicating the button. Unless turnleft is a string variable, you probably meant to put quotes "Turn Left" or something like that.
  5. The last line is missing a semi-colon.

Also, logically, your code is also wrong because:

  1. Your throttle will only have any effect the first frame the button is pushed.
  2. update is never called. You probably meant Update.
  3. The if statements outside of update will never have any effect.
  4. Even if your forward is your vertical and your right is your forward, your descend will ascend.
  5. Your turn left will ascend, not turn.
  6. You should be multiplying your throttle change by Time.deltaTime.
  7. You should be using one of your transform axes instead of position.x explicitly for your throttle.
  8. You should probably be using throttleSpeed somewhere. Probably where you check for throttle.

Some notes:

  1. You would be better off using axes rather than defining individual buttons for movements like turning, etc.
  2. Planes turn to face a direction and move in that direction, so it might be wise to tilt the plane rather than move it up and down immediately when ascending/descending.
  3. You should maintain a speed by which you move and add to that with throttle, rather than requiring the user to hammer throttle repeatedly to go anywhere.
  4. Does the plane just float in space or should there be some gravity?

If you want to know if your script is correct, you should try it yourself. If you're new to scripting, try one of the tutorials and look at their code.

A simple start would be something like:

var throttleSpeed : float = 5.0;
var turnSpeed : float = 15.0;
private var speed : float = 0.0;

function Update() {
     speed += Input.GetAxis("Throttle") * Time.deltaTime * throttleSpeed;
     var h : float = Input.GetAxis("Horizontal") * Time.deltaTime * turnSpeed;
     var v : float = Input.GetAxis("Vertical") * Time.deltaTime * turnSpeed;
     transform.eulerAngles.y += h;
     transform.eulerAngles.x += v;
     transform.position += transform.forward * speed;
     //Do some stuff with gravity, checking if grounded, etc.
}