'else' won't work in an if statement

Here is my code:

#pragma strict

var walkSpeed = 0.2;
var runSpeed = 1;
var flySpeed = 3;

function Start () {

}

function Update () {
if	(Input.GetAxis("Vertical"));
		animation.CrossFade("Walk_") = walkSpeed;
	else
		animation.CrossFade("Rest");

}

Whenever I try to use ‘else’ this comes up:

BCE0044: expecting }, found ‘else’.

Is there a new code for if statements instead of else? I’ve heard you use OR or || for something in if statements but none seem to work for me…

Does anyone have an answer?

Thanks

Ok, so since this has been answered in the comments and I don’t have the privileges to convert comments to answers, I will post my own.

The problem you had, was that you were using the wrong syntax for and if statement.
Like in many other languages, javascript and therefore unityscript uses {} curlybrackets for code wrapping, including an if-else statement.
Also present in many other languages is the usage of a ; semicolen for EOL (end of line), this is used for every line of code that is executed individually.

Therefore your code should look like this:

function Update() {
    if (/*Your expression for the if statement*/) {
        //code here
    }
    else {
        //code here
    }
}

You can also stack an if on top of an else:

if (/*your expression here*/) {
    //Your code
}
else if (/*Your second expression here) {
    //Your code
}
else {
    //Your code
}

To use an or expression, in javascript and unityscript, you use ||
So if I want my code to happen when either a or b are true:

true || true //evaluates as true
true || false //evaluates as true
false || false //evaluates as false
false || (true || false) //evaluates as true

And is done similarly with &&

true && true //evaluates as true
true && false //evaluates as false
false && false //evaluates as false
true && (true || false) //evaluates as true

You can also allways use not, which inverts the evaluation and is done using a !

!true //evaluates as false
!false //evaluates as true
!(true && true) //evaluates as false
!(true && false) //evaluates as true
!(false && false) //evaluates as true

I suggest learning these basics before starting anything big :slight_smile:

Hope this helps,
Benproductions1