- Home /
Animation script error
So i followed a tutorial and typed up the code its hard to read the code from the tutorial cause its on youtube and im getting a couple errors.. heres my code:
> function Start () {
>
> }
>
> function Update () { 	PlayerAnims
> (); 	PlayerStateController (); 	
> }
>
> function PlayerStateController () {
> 	if
> (Input.GetAxis("Vertical"))
> !=0 ||
> Input.GetAxis("horizontal")
> !=0)) 	{ 	if
> (Input.GetButton ("Sprint"))
> 	{ 	PlayerState = 3; 	}
> 	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("Idleanimation",
> 0.4);
>
> 	} 	else if (PlayerState
> == 2) 	{
> 	PlayerAnimSec.animation.CrossFade("sprint
> animation", 0.4);
>
> 	} 	 }
and im getting these errors:
Assets/scripts/player.js(22,21): BCE0044: expecting :, found '='.
Assets/scripts/player.js(20,40): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/scripts/player.js(20,9): BCE0043: Unexpected token: if.
Assets/scripts/player.js(18,78): BCE0043: Unexpected token: ).
Assets/scripts/player.js(18,40): BCE0043: Unexpected token: !=.
Answer by Adamcbrz · Dec 14, 2012 at 04:30 AM
First please make sure you insert your code into a code block before posting because its hard to follow along which will make alot of people just skipped past it.
It looks like you are missing a couple of semicolons.
PlayerState = 1
AND
PlayerState = 0
Adding the semicolons there did not affect anything it is still displaying the error messages
Ok I went through and added tried to debug your script I think this one should be error free. I had to guess at your variable declarations since you didn't include those.
var PlayerState : int = 0; var PlayerAnimSec : GameObject;
function Start () {
}
function Update () { PlayerAnims(); PlayerStateController(); }
function PlayerStateController () { if(Input.GetAxis("Vertical") || Input.GetAxis("horizontal")) { if(Input.GetButton ("Sprint")) { PlayerState = 2; } else { PlayerState = 1; } } else { PlayerState = 0; } }
function PlayerAnims () { if(PlayerState == 0) { PlayerAnimSec.animation.CrossFade("idleanimation", 0.4); } else if (PlayerState == 1) { PlayerAnimSec.animation.CrossFade("Idleanimation", 0.4); } else if (PlayerState == 2) { PlayerAnimSec.animation.CrossFade("sprint animation", 0.4); } }
You need to EDIT your question and FOR$$anonymous$$AT your code correctly.
Your answer
Follow this Question
Related Questions
Why isn't my java code working? 2 Answers
Making an animation play when you press down 2 keys 1 Answer
Why wont my animations play? 1 Answer
SCRIPT NOT WORKING 2 Answers
Console Error 1 Answer