- Home /
What is Wrong With This Script?
function PlayerAnims()
{
if (PlayerState == 0); {
PlayerAnimSec.animation.CrossFade("IDLE ANIMATION");
else if (PlayerState == 1); {
PlayerAnimSec.animation.CrossFade("WALKING ANIMATION");
}
else if (PlayerState == 2); {
PlayerAnimSec.animation.CrossFade("SPRINTING ANIMATION");
}
}
Here's what the console says:
Assets/Player ANIMATION.js(37,60): BCE0044: expecting :, found ';'.
Line 37 is the line that says: PlayerAnimSec.animation.CrossFade("IDLE ANIMATION");
It is most likely to do with the closed bracket and the semi-colon but that's just what the console says. I'm not sure if it is pin-point accurate because I'm not that experienced. I think that the problem is throughout the other two lines as well which look almost exactly the same as the one mentioned:
PlayerAnimSec.animation.CrossFade("SPRINTING ANIMATION"); AND PlayerAnimSec.animation.CrossFade("WALKING ANIMATION");
I'm relatively new to programming and Unity3d; so the simpler the better, I've definitely posted the codes right but some of the brackets may have been posted in this forum wrongly; but it should be okay.
Any Ideas? Thanks In Advance!
This is all O$$anonymous$$ now, I have other problems but they can not really be fixed in a forum so thanks. I will re-post my question on decompressing.
Answer by RonHiler · Oct 23, 2012 at 05:40 PM
Here is the code that you want
function PlayerAnims()
{
if (PlayerState == 0)
{
PlayerAnimSec.animation.CrossFade("IDLE ANIMATION");
}
else if (PlayerState == 1)
{
PlayerAnimSec.animation.CrossFade("WALKING ANIMATION");
}
else
{
PlayerAnimSec.animation.CrossFade("SPRINTING ANIMATION");
}
}
If you find yourself writing lots of if/if else/else blocks like this, consider replacing with a Switch() statement instead. But this should get you started for now.
Answer by MarkFinn · Oct 13, 2012 at 03:54 PM
Remove the semicolon in the line that says
if (PlayerState == 0); {
It should say
if (PlayerState == 0) {
And the same in the lines
else if (PlayerState == 1); {
and
else if (PlayerState == 2); {
Should be no semi-colons in any of them.
I added them because without them even more errors came up? BUT that console error did slightly change but now there are 4
is PlayerAnimSec a gameObject? is it initialized? what are the new errors? I notice you are also missing a closing bracket after the first if:
if (PlayerState == 0); {
PlayerAnimSec.animation.CrossFade("IDLE ANI$$anonymous$$ATION");
}// add this
else if (PlayerState == 1); {
Trust me, they definitely should not be there. They are just hiding the real errors by making earlier errors. I recommend asking about the previous errors ins$$anonymous$$d.
the }// helped, thanks! For your questions i don't reeeeeeallly know what PlayerAnimSec(tion?) is. The 2 errors after putting in the 2 / after the } are as follow:
Assets/Player ANI$$anonymous$$ATION.js(44,1): BCE0043: Unexpected token: else.
Assets/Player ANI$$anonymous$$ATION.js(44,5): UCE0001: ';' expected. Insert a semicolon at the end.
Another question unrelated to this; why cant i install the unity tree package of the unity website, it says that it fails to decompress the custom pack;
Error while importing package: Couldn't decompress package its the http://unity3d.com/support/resources/assets/terrain-assets
Answer by Dan 58462 · Oct 14, 2012 at 12:10 PM
Ok, I will remove the semi-colons again but , Seth what do you mean by I am missing a closing bracket? P.S: A lot of this is from tutorials
Your answer
Follow this Question
Related Questions
3 errors in scrip. 1 Answer
Internal Compiler Error 1 Answer
What is wrong with these two lines of scripting? 1 Answer
What is Wrong With This Section of my Script? 1 Answer
Console Error while in editior 4 Answers