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);
}
}
}
}
}
copy and paste the full error message, it includes more info like line numbers that will help this out
when you define a function like on line 21, that should not have a semicolon
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
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.
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.