- Home /
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){
}
}
}
}
Is that your entire file? The compiler error mentions lines 61, 64 and 119, but the code you posted has only 57 lines.
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--->}
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.
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.
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--->}
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.
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.
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...
Your answer
Follow this Question
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