• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
-1
Question by TopazX · Nov 21, 2012 at 01:37 AM · fps

I dont know whats wrong with my script

var Playerstate : float; var PlayerAnimSec : GameObject;

function Update () ) PlayerStateController(); PlayerAnims(); around here is were it is wrong )

function PlayerStateController() ( if ((input.GetAxis("Vertical")!=0 ||input.Get Axis("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("Walking Animation", 0.4); ) else if (Playerstate == 2) ( PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4); )

  • Formatted code (looks like there are no curly braces, code is as in the above original post) :

    var Playerstate : float; var PlayerAnimSec : GameObject;

    function Update () ) PlayerStateController(); PlayerAnims(); around here is were it is wrong )

    function PlayerStateController() ( if ((input.GetAxis("Vertical")!=0 ||input.Get Axis("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("Walking Animation", 0.4); ) else if (Playerstate == 2) ( PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4); )

Comment
Add comment · Show 3
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 DaveA · Nov 21, 2012 at 01:38 AM 1
Share

Please edit and format your code with the 101/010 button Also tell us what you think is wrong. Was there an error message?

avatar image AlucardJay · Nov 21, 2012 at 05:00 AM 0
Share

To help the new user and with their karma, I have edited the question. TopazX , as Dave said, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

And tell us what you think is wrong, what is happening?

avatar image AlucardJay · Nov 21, 2012 at 05:02 AM 0
Share

Just before starting to edit, I see you have no curly braces { or }

Please check your code, and post the current code you are using.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chelnok · Nov 21, 2012 at 05:23 AM

Looks like you are using parentheses when you should use curly brackets.

You code: function PlayerStateController() ( if ... )

Should be: function PlayerStateController() { if ... }

Example for correct way to use them:

 function Update ()
 {
     if (something == 1) 
     {
         doSomething();
     }
     else
     {
         doSomethinElse();
     }
 }
 
 function doSomething()
 {
     print("Learing to fly");
 }


You might want to learn some basics of coding.

Here is some basics about javascript in Unity: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Character Respawn 1 Answer

FPS RIGIDBODY PROBLEM 1 Answer

Weapon Possition Move On Sprint 1 Answer

collider doesnt react to script 0 Answers

Question about FPS Player Script 1 Answer


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