Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

error CS1525: Unexpected symbol `end-of-file'- keeps coming up

Discussion in 'Editor & General Support' started by kentg1, Apr 26, 2017.

  1. kentg1

    kentg1

    Joined:
    Dec 22, 2014
    Posts:
    168

    I have added curly brackets at the end of the script and taken them away - all to no avail? Still same error message




    private bool isGrounded()

    {
    if (myRigidbody.velocity.y <= 0)
    foreach (Transform point in groundPoints)
    {
    Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);
    {

    for (int i = 0; i < colliders.Length; i++)
    {
    {
    if (colliders.gameObject != gameObject)


    return true;
    {



    return false;
    }
    }
    }

    }
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Use [code ] [/code] tags and post the entire script. If this is the entire script, it probably doesn't work because your code isn't in a class definition.
     
  3. kentg1

    kentg1

    Joined:
    Dec 22, 2014
    Posts:
    168
    Code (csharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class Player : MonoBehaviour {
    8.  
    9.     public Rigidbody2D myRigidbody;
    10.  
    11.     private Animator myAnimator;
    12.  
    13.     public float playerSpeed;
    14.  
    15.     private bool attack;
    16.  
    17.     private bool slide;
    18.  
    19.     private bool jump;
    20.  
    21.     private float jumpForce;
    22.  
    23.  
    24.     private bool faceRight;
    25.  
    26.     [SerializeField]
    27.     private Transform[] groundPoints;
    28.  
    29.     [SerializeField]
    30.     private float groundRadius;
    31.  
    32.     [SerializeField]
    33.     private LayerMask whatIsGround;
    34.  
    35.  
    36.     // Use this for initialization
    37.     void Start ()
    38.     {
    39.  
    40.         faceRight = true;
    41.         myRigidbody = GetComponent<Rigidbody2D> ();
    42.         myAnimator = GetComponent<Animator> ();
    43.  
    44.     }
    45.  
    46.     void Update()
    47.     {
    48.         HandleInput ();
    49.  
    50.     }      
    51.  
    52.     // Update is called once per frame
    53.     void FixedUpdate () {
    54.  
    55.         float horizontal = Input.GetAxis ("Horizontal");
    56.  
    57.         isGrounded = isGrounded();
    58.  
    59.         ourMovement (horizontal);
    60.  
    61.         Flip(horizontal);
    62.  
    63.         HandleAttacks ();
    64.  
    65.         ResetValues ();
    66.  
    67.     }
    68.  
    69.     private void ourMovement(float horizontal)
    70.     {
    71.  
    72.         if (!myAnimator.GetBool("slide") && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
    73.         {
    74.             myRigidbody.velocity = new Vector2(horizontal * playerSpeed, myRigidbody.velocity.y);
    75.         }
    76.  
    77.         if (isGrounded && jump)
    78.  
    79.         {
    80.             isGrounded = false;
    81.             myRigidbody.AddForce(new Vector2(0f, 400));
    82.         }
    83.  
    84.  
    85.         if(isGrounded && slide && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("slide"))
    86.         {
    87.             myAnimator.SetBool ("slide", true);
    88.         }
    89.  
    90.         else if (this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("slide"))
    91.  
    92.         {
    93.             myAnimator.SetBool ("slide", false);
    94.         }
    95.  
    96.  
    97.         myAnimator.SetFloat ("speed", Mathf.Abs (horizontal));
    98.     }
    99.  
    100.     private void HandleAttacks()
    101.     {
    102.         if (attack)
    103.         {
    104.             myAnimator.SetTrigger ("attack");  
    105.             myRigidbody.velocity = Vector2.zero;
    106.         }
    107.  
    108.     }
    109.  
    110.     private void HandleInput()
    111.     {
    112.  
    113.     if (Input.GetKeyDown(KeyCode.Space))
    114.  
    115.     {
    116.  
    117.             jump = true;
    118.  
    119.     }
    120.         if (Input.GetKeyDown(KeyCode.LeftShift))
    121.         {
    122.             attack = true;
    123.         }
    124.  
    125.         if (Input.GetKeyDown (KeyCode.LeftControl))
    126.  
    127.             {
    128.                 slide = true;
    129.             }
    130.  
    131.     }
    132.  
    133.     private void Flip(float horizontal)
    134.     {
    135.         if (horizontal > 0 && !faceRight || horizontal < 0 && faceRight)
    136.  
    137.         {
    138.             faceRight = !faceRight;
    139.  
    140.             Vector3 theScale = transform.localScale;
    141.  
    142.  
    143.             theScale.x *=-1;
    144.             transform.localScale = theScale;
    145.  
    146.         }
    147.     }
    148.  
    149.     private void ResetValues()
    150.  
    151.     {
    152.         attack = false;
    153.         slide = false;
    154.  
    155.     }
    156.  
    157.     private bool isGrounded()
    158.  
    159.     {
    160.         if (myRigidbody.velocity.y <= 0)
    161.  
    162.             foreach (Transform point in groundPoints)
    163.  
    164.             {
    165.                 Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);
    166.                   {
    167.                    
    168.                     for (int i = 0; i < colliders.Length; i++)
    169.  
    170.                     {                  
    171.  
    172.                         {
    173.                             if (colliders[i].gameObject != gameObject)
    174.  
    175.                            
    176.                                
    177.                                     return true;
    178.                         {
    179.        
    180.            
    181.            
    182.                 return false;
    183.  
    184.                     }  
    185.                 }  
    186.             }
    187.         }
    188.    
    189.  
    190.  
     
  4. kentg1

    kentg1

    Joined:
    Dec 22, 2014
    Posts:
    168
    Sorry this is the full error message

    Assets/scripts/Player.cs(187,246): error CS1525: Unexpected symbol `end-of-file'
     
  5. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    You're missing at least 3 closing brackets and other stuff too.

    Basically, it looks like (as the error says) you only have the upper portion of the script and the rest is literally missing. Wherever you copy-pasted this from, try again?
     
  6. kentg1

    kentg1

    Joined:
    Dec 22, 2014
    Posts:
    168
    If you scroll down to the bottom is has the entire script and from what I have researched it looks like I am missing or have too many { } brackets. somewhere, I just added some lines of code to a existing script?

    Thanks
     
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    The script appears incomplete, you should double check the original source.