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

I Need Help With A Script

Discussion in 'Editor & General Support' started by Blechgames, Jan 3, 2020.

  1. Blechgames

    Blechgames

    Joined:
    Jan 1, 2020
    Posts:
    1
    Hey, so I'm very, VERY new to Unity (only 5 days in) and I'm trying out my first test project, mainly trying to get stuff written down for when I code in the future. However, I am having an issue. There is one error in my script, and it simply says "Error CS1002: ; expected" However, when I put the symbol there asking for, a ton of errors pop up. And, as I've said, I'm new to Unity Codding, so if someone could help, that would be appreciated!

    Heres the script:

    using UnityEngine;

    public class CursorLockExample : MonoBehaviour
    {
    void Update()
    {
    //Press the space bar to apply no locking to the Cursor
    if (Input.GetKey(KeyCode.Space))
    Cursor.lockState = CursorLockMode.None;
    }

    void OnGUI()
    {
    //Press this button to lock the Cursor
    if (GUI.Button(new Rect(0, 0, 100, 50), "Lock Cursor"))
    {
    Cursor.lockState = CursorLockMode.Locked;
    }

    //Press this button to confine the Cursor within the screen
    if (GUI.Button(new Rect(125, 0, 100, 50), "Confine Cursor"))
    {
    Cursor.lockState = CursorLockMode.Confined;
    }
    }
    }
     
  2. Hozepha

    Hozepha

    Joined:
    Aug 9, 2018
    Posts:
    2
    which ide do you usde? Please provide a screenshot before and after the "bunch of errors"
     
  3. Hozepha

    Hozepha

    Joined:
    Aug 9, 2018
    Posts:
    2
    i'll be glad to help you out if i could understand what are the errors show after you've written down the semi colon
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    Sometimes when you fix one error the compiler will report more errors than before. That doesn't always mean that you have more errors than before, though. When you fix one error then the compiler will be able to interpret your code more clearly and that will allow it to identify errors that were always there, but it couldn't find before.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    That exact script works for me. Please post the exact error, and a screenshot. Where did you get this code?