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. Dismiss Notice

Question 3 errors cs1513, cs8803, cs1022

Discussion in 'Getting Started' started by bruhdishard, Jul 24, 2023.

  1. bruhdishard

    bruhdishard

    Joined:
    May 15, 2022
    Posts:
    2
    Assets\LadderScr.cs(26,6): error CS1513: } expected,

    Assets\LadderScr.cs(31,5): error CS8803: Top-level statements must precede namespace and type declarations.,

    Assets\LadderScr.cs(41,1): error CS1022: Type or namespace definition, or end-of-file expected
    .

    I am trying to make a vine that you can climb on like a ladder, and these errors appeared.
    I am a beginner, so my code is probably really bad.
    my code:
    Assets\LadderScr.cs(26,6): error CS1513: } expected,

    Assets\LadderScr.cs(31,5): error CS8803: Top-level statements must precede namespace and type declarations.,

    Assets\LadderScr.cs(41,1): error CS1022: Type or namespace definition, or end-of-file expected
    .

    I am trying to make a vine that you can climb on like a ladder, and these errors appeared.
    I am a beginner, so my code is probably really bad.
    my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LadderScr : MonoBehaviour {
    public Rigidbody2D rb;
    public bool onLadder;
    public bool usingLadder;
    void OnTriggerEnter2D(Collider2D col)
    {
    if (col.gameObject.tag == "Ladder")
    {
    onLadder = true;
    }
    }
    void OnTriggerExit2D(Collider2D col)
    {
    if (col.gameObject.tag == "Ladder")
    {
    onLadder = false;
    rb.gravityScale = origsc;
    }
    }
    // Start is called before the first frame update
    void Start()
    {
    public float origsc = rb.gravityScale;
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetAxisRaw("Vertical") > 0)
    {
    if (onLadder == true)
    {
    rb.gravityScale = 0f;
    }
    }
    }
    }

    I dont know what to do at this point.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Use code tags when posting code.

    You have a typo somewhere. Either you are missing a } somewhere or you have another typo that makes the compiler think you're missing a } somewhere. The error points to line 26, go to that line and see what you can find. Count your { and }, make sure there are the same number and they properly match up.
     
  3. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    You have put a public variable inside your Start method. You can only put those outside of methods (like you did with all your other public variables).
    What you should have is
    public float origsc;
    up where all your other public variables are, and then in your Start method just put
    origsc = rb.gravityScale;
     
    Bunny83 likes this.
  4. bruhdishard

    bruhdishard

    Joined:
    May 15, 2022
    Posts:
    2
    Solved! Thank you.