Sorry to tell you that, but you have obviously no idea how to to code and for that this is way too complex. You don’t understand even the basics about syntax. That’s why I propose you to start with even simpler examples.
I haven’t tested the code, but I expect it should be nearly like that.
var PlayerState : float;
var PlayerAnimSec : GameObject;
function Update () {
PlayerStateController();
PlayerAnimSec();
}
function PlayerStateController() {
if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) {
if (Input.GetButton("Sprint")) {
PlayerState = 2;
} else {
PlayerState = 1;
}
} else {
PlayerState = 0;
}
}
function PlayerAnims() {
if (PlayerState == 0) {
PlayerAnimSec.animation.CrossFade("Idle Animation", 0.4);
} else if (PlayerState == 1) {
PlayerAnimSec.animation.CrossFade("Walk Animation", 0.4);
} else if (PlayerState == 2) {
PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4);
}
}
Use common sense more when looking at brackets, between your if and else statements your brackets were quite much completely inverse.
{This is between brackets}
(So is this)
[And this]
}but thats what you did {
Also the console spits out quite exact error messages. In this case an error seems to be at line 10, character 5 of player.js, but looking at your last posted version theres no object reference on line 10, thus rendering this message useless to us without the updated code. (Unless Inpu.GetAxis is not a correct reference you used, but it seems correct to me, it is starting on line 10, ch5 though…)
Maybe by looking at firstpersoncontroller.js (in standard assets) you can find an implication that works