Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dan 58462 · Oct 13, 2012 at 03:32 PM · errorconsolestuckexpecting

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!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dan 58462 · Oct 23, 2012 at 03:17 PM 0
Share

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.

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dan 58462 · Oct 14, 2012 at 07:47 AM 0
Share

I added them because without them even more errors came up? BUT that console error did slightly change but now there are 4

avatar image Seth-Bergman · Oct 14, 2012 at 08:46 AM 0
Share

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); {

avatar image MarkFinn · Oct 14, 2012 at 11:19 AM 0
Share

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.

avatar image Dan 58462 · Oct 14, 2012 at 11:33 AM 0
Share

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.

avatar image Dan 58462 · Oct 14, 2012 at 12:05 PM 0
Share

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

Show more comments
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges