Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

(83,2): error CS1513: } expected

Discussion in 'Scripting' started by ImGundulf, May 22, 2020.

  1. ImGundulf

    ImGundulf

    Joined:
    May 17, 2020
    Posts:
    49
    hello, I can't find where I did wrong with not placing a "}". Here's the code;
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Ball : MonoBehaviour {
    6.  
    7.     public float moveSpeed = 12.0f;
    8.  
    9.     public Vector2 ballDirection = Vector2.left;
    10.  
    11.     private float playerPaddleHeight, playerPaddleWidth, computerPaddleHeight, computerPaddleWidth, playerPaddleMaxX, playerPaddleMaxY, playerPaddleMinX, playerPaddleMinY, computerPaddleMaxX, computerPaddleMaxY, computerPaddleMinX, computerPaddleMinY, ballWidth, ballHeight;
    12.  
    13.     private GameObject paddlePlayer, paddleComputer;
    14.  
    15.  
    16.  
    17.     // Start is called before the first frame update
    18.     void Start() {
    19.  
    20.         paddlePlayer = GameObject.Find ("player_paddle");
    21.         paddleComputer = GameObject.Find ("computer_paddle");
    22.  
    23.         playerPaddleHeight = paddlePlayer.transform.GetComponent<SpriteRenderer>().bounds.size.y;
    24.         playerPaddleHeight = paddlePlayer.transform.GetComponent<SpriteRenderer>().bounds.size.x;
    25.         computerPaddleHeight = paddleComputer.transform.GetComponent<SpriteRenderer>().bounds.size.y;
    26.         computerPaddleHeight = paddleComputer.transform.GetComponent<SpriteRenderer>().bounds.size.x;
    27.         ballHeight = transform.GetComponent<SpriteRenderer> ().bounds.size.y;
    28.         ballHeight = transform.GetComponent<SpriteRenderer> ().bounds.size.x;
    29.  
    30.         playerPaddleMaxX = paddlePlayer.transform.localPosition.x + playerPaddleWidth / 2;
    31.         playerPaddleMaxX = paddlePlayer.transform.localPosition.x - playerPaddleWidth / 2;
    32.  
    33.         computerPaddleMaxX = paddleComputer.transform.localPosition.x - computerPaddleWidth / 2;
    34.         computerPaddleMaxX = paddleComputer.transform.localPosition.x + computerPaddleWidth / 2;
    35.  
    36.        
    37.     }
    38.  
    39.     // Update is called once per frame
    40.     void Update() {
    41.        
    42.         Move ();
    43.     }
    44.  
    45.     bool CheckCollision () {
    46.  
    47.         playerPaddleMaxY = paddlePlayer.transform.localPosition.y + playerPaddleHeight / 2;
    48.         playerPaddleMinY = paddlePlayer.transform.localPosition.y - playerPaddleHeight / 2;
    49.  
    50.         computerPaddleMaxY = paddleComputer.transform.localPosition.y + computerPaddleHeight / 2;
    51.         computerPaddleMinY = paddleComputer.transform.localPosition.y - computerPaddleHeight / 2;
    52.  
    53.         if (transform.localPosition.x - ballWidth / 2 < playerPaddleMaxX && transform.localPosition.x + ballWidth / 2 > playerPaddleMinX) {
    54.  
    55.             if (transform.localPosition.y - ballHeight / 2 < playerPaddleMaxY && transform.localPosition.y + ballHeight / 2 > playerPaddleMinY) {
    56.  
    57.                 ballDirection = Vector2.right;
    58.                 transform.localPosition = new Vector3 (playerPaddleMaxX + ballWidth / 2, transform.localPosition.y, transform.localPosition.z); {
    59.                 return true;
    60.             }
    61.         }
    62.  
    63.         if (transform.localPosition.x + ballWidth / 2 > computerPaddleMaxX && transform.localPosition.x - ballWidth / 2 < computerPaddleMinX) {
    64.  
    65.             if (transform.localPosition.y - ballHeight / 2 > computerPaddleMaxY && transform.localPosition.y + ballHeight / 2 > computerPaddleMinY) {
    66.  
    67.                 ballDirection = Vector2.left;
    68.                 transform.localPosition = new Vector3 (computerPaddleMaxX - ballWidth / 2, transform.localPosition.y, transform.localPosition.z);
    69.                 return true;
    70.             }
    71.         }
    72.  
    73.         return false;
    74.     }
    75.  
    76.     void Move () {
    77.  
    78.         if (!CheckCollision ()) {
    79.  
    80.             transform.localPosition += (Vector3)ballDirection * moveSpeed * Time.deltaTime;
    81.         }
    82.     }
    83. }
    84.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    copying and pasting the exact error message would help. The error message has a line number.
     
  3. ProntName

    ProntName

    Joined:
    Apr 27, 2020
    Posts:
    15
    I believe you have an extra curly bracket on line 58?
     
    StarManta and PraetorBlue like this.