im new to unity coding and whenever i try to run my game it comes up with this error in the shooting script
assets\scripts\Gunfire.sc(5,37): error CS1003: Syntax Error, ‘,’ expected
this is my script
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);
}
}
}
Before we even get into any syntax errors, is this the correct file?
Your error mentions “Gunfire.sc”. This class is called “gun”.
Two problems with that:
The correct file extension for a script is “.cs”, not “.sc”
The filename must match your class name. So if your file is called “Gunfire.cs”, your class must be named “Gunfire”. “gun” is not correct.
Now onto syntax errors:
Lines 7 and 8 both end with colons but they are supposed to end with semicolons.
This is a colon :
This is a semicolon ;
1 Like
PraetorBlue:
Before we even get into any syntax errors, is this the correct file?
Your error mentions “Gunfire.sc”. This class is called “gun”.
Two problems with that:
The correct file extension for a script is “.cs”, not “.sc”
The filename must match your class name. So if your file is called “Gunfire.cs”, your class must be named “Gunfire”. “gun” is not correct.
Now onto syntax errors:
Lines 7 and 8 both end with colons but they are supposed to end with semicolons.
This is a colon :
This is a semicolon ;
thank you this fixed the issue!
Excellent! For your future reference, here is how to understand compiler and other errors and even fix them yourself:
https://discussions.unity.com/t/824586/8