please fix parsing error
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour { [SerializeField] private float movementspeed; private Rigidbody2D myRigidBody; private Animator myAnimator; private bool facingRight; private bool attack; private bool slide;
// Use this for initialization
void Start (){
facingRight = true;
myRigidBody = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
}
void Update(){
HandleInput();
}
// Update is called once per frame
void FixedUpdate ()
{
float Horizontal = Input.GetAxis ("Horizontal");
HandleMovement (Horizontal);
Flip (Horizontal);
HandleAttacks ();
ResetValues ();
}
private void HandleMovement(float Horizontal) {{ if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack")) { myRigidBody.velocity = new Vector2 (Horizontal * movementspeed, myRigidBody.velocity.y); }
if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")){
myAnimator.SetBool("slide" , true);
}
else if(!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("slide")
myAnimator.SetBool("slide" , false);
}
myAnimator.SetFloat ("speed", Mathf.Abs(Horizontal));}
private void HandleAttacks(){
if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack"))
{
myAnimator.SetTrigger ("attack");
myRigidBody.velocity = Vector2.zero;}
}
private void HandleInput()
{
if (Input.GetKeyDown (KeyCode.LeftShift))
{
attack = true;
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
slide = true;
}
}
private void Flip(float Horizontal)
{ if (Horizontal > 0 && !facingRight || Horizontal < 0 && facingRight) {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
private void ResetValues(){
attack = false;
slide = false;
}
Answer by Ali-hatem · Aug 27, 2016 at 12:14 PM
public class Player : MonoBehaviour {
[SerializeField] private float movementspeed;
private Rigidbody2D myRigidBody;
private Animator myAnimator;
private bool facingRight;
private bool attack; private bool slide;
void Start (){
facingRight = true;
myRigidBody = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
}
void Update(){
HandleInput();
}
void FixedUpdate () {
float Horizontal = Input.GetAxis ("Horizontal");
HandleMovement (Horizontal);
Flip (Horizontal);
HandleAttacks ();
ResetValues ();
}
private void HandleMovement(float Horizontal) {
if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack")) {
myRigidBody.velocity = new Vector2 (Horizontal * movementspeed, myRigidBody.velocity.y);
}
if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")){
myAnimator.SetBool("slide" , true);
}
else if(!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("slide")){
myAnimator.SetBool("slide" , false);
myAnimator.SetFloat ("speed", Mathf.Abs(Horizontal));
}
}
private void HandleAttacks(){
if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack")) {
myAnimator.SetTrigger ("attack");
myRigidBody.velocity = Vector2.zero;}
}
private void HandleInput(){
if (Input.GetKeyDown (KeyCode.LeftShift)) {
attack = true;
}
if (Input.GetKeyDown(KeyCode.LeftControl)){
slide = true;
}
}
private void Flip(float Horizontal){
if (Horizontal > 0 && !facingRight || Horizontal < 0 && facingRight) {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
private void ResetValues(){
attack = false;
slide = false;
}
}
note : to avoid same errors again
add the needed brackets before righting any code or jumping to another test statement or function.
add spaces between statement & functions .
double click the errors in unity will take you to the line where the error is.
good luck.
Your answer
Follow this Question
Related Questions
error CS8025: Parsing error 0 Answers
error CS8025 (Parsing Error) 1 Answer
Parsing Error 0 Answers
Simple light switch problem 0 Answers
Parsin Error (C#) 2 Answers