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 Hris · Aug 08, 2014 at 10:58 AM · cs8025cs1525

If CODE problems..

Hi I am pretty new at this, but it keeps telling me something is wrong with this code, if anyone can take a look and help me?

ERRORS:

 Assets/PlayerStuff/Scripts/MovmentScript.cs(61,57): error CS1525: Unexpected symbol `{'
 Assets/PlayerStuff/Scripts/MovmentScript.cs(64,59): error CS1525: Unexpected symbol `{'
 Assets/PlayerStuff/Scripts/MovmentScript.cs(119,1): error CS8025: Parsing error

CODE:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof (Animator))]
 [RequireComponent(typeof (CapsuleCollider))]
 [RequireComponent(typeof (Rigidbody))]
 public class MovmentScript : MonoBehaviour {
 
     public float animSpeed = 1f;                
     public float lookSmoother = 3f;                
     float animSpeedy = 1.5f;                    
     
     private Animator anim;                            
     private AnimatorStateInfo currentBaseState;        
     private CapsuleCollider col;                    
 
     static int idleState = Animator.StringToHash("Base Layer.Idle");
     static int idleToStrafeState = Animator.StringToHash("Base Layer.IdleToStrafe");
     static int idleToStrafeSState = Animator.StringToHash("Base Layer.IdleToStrafeS");
     static int walkingState = Animator.StringToHash("Base Layer.Walking");            
     static int sprintState = Animator.StringToHash("Base Layer.Sprint");                
     static int sprintForwardToIdleState = Animator.StringToHash("Base Layer.SprintForwardToIdle");        
 
 
     // Use this for initialization
     void Start () {
         // initialising reference variables
         anim = GetComponent<Animator>();                      
         col = GetComponent<CapsuleCollider>();                
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void FixedUpdate (){
         float h = Input.GetAxis ("Horizontal");                
         float v = Input.GetAxis ("Vertical");                
         anim.SetFloat ("UD", v);                                
         anim.SetFloat ("LR", h);                             
         anim.SetBool ("Sprint", false);                        
         anim.speed = animSpeed;                                
         currentBaseState = anim.GetCurrentAnimatorStateInfo (0);    // set our currentState variable to the current state of the Base Layer (0) of animation
 
         if(currentBaseState.nameHash == walkingState || currentBaseState.nameHash == idleState){
             if(Input.GetButtonDown("Sprint"){
                 anim.SetBool("Sprint", true);
             }
             else(anim.SetBool("Sprint", false){
 
             }
             
         }
       }
 }
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 rutter · Aug 08, 2014 at 08:30 AM 0
Share

Is that your entire file? The compiler error mentions lines 61, 64 and 119, but the code you posted has only 57 lines.

avatar image Hris · Aug 08, 2014 at 09:20 AM 0
Share

That is my code with out my comments the lines in question are:

  if(currentBaseState.nameHash == walkingState || currentBaseState.nameHash == idleState){
 THIS--->if(Input.GetButtonDown("Sprint"){
 anim.SetBool("Sprint", true);
 }
 THIS--->else(anim.SetBool("Sprint", false){
  
 }
  
 }
 }
 THIS--->}

avatar image gjf · Aug 08, 2014 at 11:08 AM 0
Share

it's important that you post unedited code where line numbers are referenced. conta$$anonymous$$ating it with additional comments to highlight where you think the error might be often makes it more difficult for people to help...

it looks like your braces are mismatched especially on the latest snippet - the code after the else statement probably needs an opening brace.

if you format your code properly in your editor, spotting mismatched braces will be easier and, overall, your code will be easier to read and make your understanding more likely.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jamesflowerdew · Aug 08, 2014 at 11:12 AM

you're missing a bracket on your if, and using the wrong symbols to open/close your else...

if(Input.GetButtonDown("Sprint")){

} else{

anim.SetBool("Sprint", false);

}

other errors may disappear when this is sorted, but you may have too many wiggly brackets or too few at the end.

Comment
Add comment · Show 1 · 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 Hris · Aug 08, 2014 at 06:54 PM 0
Share

jamesflowerdew - You fixed one of the errors with the if, I counted the {} brackets they are exactly as needed each opened bracket has a close bracket yet it complains about the last one.

 Assets/PlayerStuff/Scripts/$$anonymous$$ovmentScript.cs(64,52): error CS1525: Unexpected symbol `{'
 Assets/PlayerStuff/Scripts/$$anonymous$$ovmentScript.cs(71,1): error CS8025: Parsing error
 

Now it was saying my comments had a issue... so I removed them will post the code now below.

     void FixedUpdate (){
         float h = Input.GetAxis ("Horizontal");                // setup h variable as our horizontal input axis
         float v = Input.GetAxis ("Vertical");                // setup v variables as our vertical input axis
         anim.SetFloat ("UD", v);                            // set our animator's float parameter 'UP' equal to the vertical input axis                
         anim.SetFloat ("LR", h);                             // set our animator's float parameter 'LF' equal to the horizontal input axis        
         anim.SetBool ("Sprint", false);                        
         anim.speed = animSpeed;                                // set the speed of our animator to the public variable 'animSpeed'
         currentBaseState = anim.GetCurrentAnimatorStateInfo(0);    // set our currentState variable to the current state of the Base Layer (0) of animation
 
         if(currentBaseState.nameHash == walkingState || currentBaseState.nameHash == idleState && Input.GetButtonDown("Sprint")){
                 anim.SetBool("Sprint", true);
             }
 THIS--->        else(anim.SetBool("Sprint", false)){
 
         }
             
         
 
     }    
 THIS--->}
avatar image
0

Answer by tanoshimi · Aug 08, 2014 at 07:12 PM

Please indent your code carefully so that {braces} are matched. That will make it much easier to see where you've got mistakes in your code.

  else(anim.SetBool("Sprint", false)){
 
 }

Should be

 else {
   anim.SetBool("Sprint", false);
 }


and the } at the end simply shouldn't be there.

Comment
Add comment · Show 3 · 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 Hris · Aug 08, 2014 at 07:19 PM 0
Share

This is where that last square bracket starts IF I remove this { and the last } I get 8 more errors!

 public class $$anonymous$$ovmentScript : $$anonymous$$onoBehaviour{

I wrote the else the way you wanted me to and it still says:

 Assets/PlayerStuff/Scripts/$$anonymous$$ovmentScript.cs(66,17): error CS1525: Unexpected symbol `}'
 Assets/PlayerStuff/Scripts/$$anonymous$$ovmentScript.cs(71,1): error CS8025: Parsing error

 else{
             anim.SetBool("Sprint", false)
 LINE:66-->        }

And as always the last } is in question.

avatar image tanoshimi · Aug 08, 2014 at 07:24 PM 1
Share

That's because now you've missed off the semicolon at the end of the line.

 anim.SetBool("Sprint", false);

Program$$anonymous$$g requires care and attention to detail...

avatar image Hris · Aug 08, 2014 at 07:30 PM 0
Share

Thank you... Sorry I really didn't see that.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I can't see the problem. 1 Answer

whats wrong with this code for a menu 3 Answers

Unexpected Symbol and Parsing Errors 0 Answers

PLEASE HELP!!!! using BergZurgArcades guide having error! 5 Answers

C# Errors CS1525,CS8025 2 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