-3

the error: a name space cannot contain members such as fields or methods


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);
    }
}

}

Egames
  • 1

1 Answers1

1

I believe you're receiving that error because you've forgotten to place the methods and variables inside of the Monobehavior brackets.

Try placing everything inside of those and see if the error persists.

IE

public class Gun : MonoBehaviour{
    variables

    methods()
}