So I’m trying to make an fps game a 3d fps an I made player movement by following this video
then i made a gun in blender then i tryed to add shooting but that’s when I ran into errors the video that i followed
. The Script I made
using UnityEngine;
public class Gun : MonoBehaviour
public float damage = 17;
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);
}
}
and the errors Assets\Gun.cs(3,33): error CS1514: { expected
Assets\Gun.cs(3,33): error CS1513: } expected
Assets\Gun.cs(28,1): error CS1022: Type or namespace definition, or end-of-file expected.
I don’t see where im missing any } or { and I don’t know what the last one is if anyone knows a solution or has a better script for making my gun shoot then reply back
You are missing a { from right after MonoBehaviour (as this is needed to start the class), and therefore you are also missing a } from the very end of the script (which would end the class).
You should post all code in code tags so that we can read it easier and see what line number the errors are referring to as well.
Newsflash: these are just fat-finger monkey-bang typos. You are capable of fixing them yourself. Here is how.
Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The complete error message contains everything you need to know to fix the error yourself.
Always start with the FIRST error in the list, as sometimes that error causes or compounds some or all of the subsequent errors.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.