Search Unity

Scripting MaxSpeed Error

Discussion in 'Scripting' started by Beast644, Aug 27, 2015.

  1. Beast644

    Beast644

    Joined:
    Aug 24, 2015
    Posts:
    16
    Trying to set the maxspeed for the player but get this error

    Assets/scripts/Player.cs(31,9): error CS1525: Unexpected symbol `}'

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Player : MonoBehaviour {
    5.  
    6.     public float maxSpeed= 3f;
    7.     public float speed = 50f;
    8.     public float jumpPower = 200f;
    9.  
    10.     public bool grounded;
    11.  
    12.     private Rigidbody2D rb2d;
    13.     private Animator anim;
    14.  
    15.     void Start ()
    16.     {
    17.         rb2d = gameObject.GetComponent<Rigidbody2D> ();
    18.         anim = gameObject.GetComponent<Animator> ();
    19.  
    20.     }
    21.  
    22.    
    23.  
    24.     void Update ()
    25.     {
    26.    
    27.    
    28.         anim.SetBool ("Grounded", grounded);
    29.         anim.SetFloat ("Speed",Mathf.Abs (Input.GetAxis("Horizontal")))
    30.  
    31.     }
    32.    
    33.    
    34.  
    35.     void FixedUpdate(){
    36.                              
    37.  
    38.         float h = Input.GetAxis ("Horizontal");
    39.  
    40.         rb2d.AddForce((Vector2.right * speed) * h);
    41.  
    42.    
    43.         if (rb2d.velocity.x > maxSpeed)
    44.         {
    45.             rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
    46.         }
    47.  
    48.         if (rb2d.velocity.x < -maxSpeed)
    49.  
    50.             rb2d.velocity = new Vector2 (-maxSpeed, rb2d.velocity.y);
    51.        
    52.         }
    53. }  
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You forgot to add a semicolon to line 29.
     
  3. Beast644

    Beast644

    Joined:
    Aug 24, 2015
    Posts:
    16
    Oh right, didn't see that. Thanks ^^