Can anyone help me with some script?

I am very new to unity and am trying to make a gun. It says no errors in visual studio but in unity says 'Error CS1002: ; expected. I am new so might be missing something, but dont see any issues.

using UnityEngine;

public class Gun : MonoBehaviour {

    public float damage = 10f;
    public float range = 100f;

    public Camera fpsCam;

    // Update is called once per frame
    void Update() {
        {

            if (Input.GetButtonDown("Fire1"))
            {
                Shoot();
            }

        }

        void Shoot();

        {
            RaycastHit hit;
            if (!Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
            {
                Debug.Log(hit.transform.name);

                Target target hit.transform.GetComponent<Target>();
                if (target != null)
                {
                    target.TakeDamage(damage);
                }
            }
        }
    }
}
  1. copy and paste the full error message, it includes more info like line numbers that will help this out
  2. when you define a function like on line 21, that should not have a semicolon
  3. If you keep track of your curly brackets, you’ll see that Shoot() is inside the Update() function, which shouldn’t happen. You’ve got an extra { after Update() I think, and looks like an extra } tacked on to the end of the script to compensate
1 Like

It’s telling you exactly what you’re missing, “Error CS1002: ; expected”

it’s expecting a ; char somewhere it think there should be one, if you’re sure there are none missing you probably have a problem with the brackets { } and it’s throwing it off.

but in your case you’ve placed one at line 21, functions don’t have semicolons on them.

The full error says Assets\Gun.cs(29,31): error CS1002: ; expected

You need to learn about syntax in C#. try this: https://learn.unity.com/tutorial/conventions-and-syntax

There are two opening brackets ({) in Update(), remove one first, then make sure Update has only one corresponding ending bracket (}). Also remove the semi colon on line 21.

1 Like

On that line, you’re missing an = after “target”

2 Likes

You are godly thank you so much