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

Please help its my first game

Discussion in '2D' started by Voltic_Toxix, Feb 17, 2020.

  1. Voltic_Toxix

    Voltic_Toxix

    Joined:
    Feb 17, 2020
    Posts:
    1
    well anyways so i was making a 2d platformer and i get a compiler error and the error is "error CS1513: } expected" n line 48 and i looked into it but i found nothing so far well if someone can help it would be much appreciated (not sure if i spelled that right lol) its in c# my code is:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class MovementManager : MonoBehaviour {
    public enum type {platformer, topDown}
    public type moveType;
    public float moveSpeed, jumpHight;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update() {
    if (Input.GetAxisRaw("Horizontal") > 0)
    {
    transform.Translate(Vector2.right * Time.deltaTime * moveSpeed);
    }
    else if (Input.GetAxisRaw("Horizontal") < 0)
    {
    transform.Translate(Vector2.left * Time.deltaTime * moveSpeed);
    }

    if (moveType == type.platformer && Input.GetAxisRaw("Vertical") > 0 && onGround)
    {
    GetComponent<Rigidbody2D>().AddForce(Vector2.up * jumpHight, ForceMode2D.Impulse);

    }
    }

    void OnCollisionEnter2D (Collision2D obj)
    {
    if (obj.gameObject.tag == "ground")
    {
    onGround = true;
    }

    void OnCollisionExit2D (Collision2D obj)
    {
    if (obj.gameObject.tag == "ground")
    {
    onGround = false;
    }
    }
    }
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,452
    First, you need to use code tags because it is almost impossible to read.
    upload_2020-2-18_8-36-34.png

    Second, although it was hard to decipher without code tags, you are missing a closing curly bracket after OnCollisionEnter2D. You closed the if statement within it but didnt close the whole OnCollisionEnter2D function. The error you posted says exactly what is wrong with your code, it will tell you the line and what is wrong.
     
  3. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
    Missing brace here ->

    void OnCollisionEnter2D(Collision2D obj)
    {
    if (obj.gameObject.tag == "ground")
    {
    onGround = true;
    } <- missing
     
    UnityMaru likes this.