Search Unity

Trouble with parsing error

Discussion in 'Scripting' started by TheDracoSlayer, Dec 1, 2015.

  1. TheDracoSlayer

    TheDracoSlayer

    Joined:
    Dec 1, 2015
    Posts:
    2
    HI I'm having a parsing error, it is used for a basic pong game
    This is what it is
    Assets/Scripts/Ball.cs(35,1): error CS8025: Parsing error

    Here is the script;
    usingUnityEngine;
    usingSystem.Collections;

    publicclassBall : MonoBehaviour {

    publicfloatballVolocity = 500;

    Rigidbodyrb;

    boolisPlay;
    intrandInt;

    voidAwake () {
    rb = gameObject.GetComponent<Rigidbody> ();
    randInt = Random.Range (1, 3);

    }

    voidUpdate () {
    if(Input.GetMouseButton(0) == true && isPlay == false)
    {
    Transform.parent = null;
    isPlay = true;
    rb.isKinematic = false;
    if(randInt == 1)
    {
    rb.AddForce(newVector3(ballVelocity,ballVelocity,0));
    }
    if(randInt == 2)
    {
    rb.AddForce(newVector3(-ballVelocity,-ballVelocity,0));
    }
    }
    }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    at a guess it's this line
    Code (csharp):
    1.  
    2. Transform.parent = null;
    3.  
    you want lowercase t transform, else you're trying to access the Class, not the local transform.

    also
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    adds line numbers and makes the code you paste in more readable, so we'd know which was line 35 (from the error message...)
     
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    The parsing error was a missing closing curly brace.
    ballVelocity declaration is spelt incorrectly.
    Missing spaces in various places.

    Here is the corrected script.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Ball : MonoBehaviour {
    5.  
    6.     public float ballVelocity = 500;
    7.  
    8.     Rigidbody rb;
    9.  
    10.     bool isPlay;
    11.     int randInt;
    12.  
    13.     void Awake () {
    14.         rb = gameObject.GetComponent<Rigidbody> ();
    15.         randInt = Random.Range (1, 3);
    16.      
    17.     }
    18.  
    19.     void Update () {
    20.         if(Input.GetMouseButton(0) == true && isPlay == false)
    21.         {
    22.             transform.parent = null;
    23.             isPlay = true;
    24.             rb.isKinematic = false;
    25.             if(randInt == 1)
    26.             {
    27.                 rb.AddForce(new Vector3(ballVelocity,ballVelocity,0));
    28.             }
    29.             if(randInt == 2)
    30.             {
    31.                 rb.AddForce(new Vector3(-ballVelocity,-ballVelocity,0));
    32.             }
    33.         }
    34.     }
    35. }
     
    Last edited: Dec 1, 2015
  4. TheDracoSlayer

    TheDracoSlayer

    Joined:
    Dec 1, 2015
    Posts:
    2
    thanks... but I already fixed XD
    however now to ball wont bounce off the wall