Physics.Raycast won't use right method

if (Input.GetButton (“Fire1”)) {
if(Physics.Raycast(ray, transform.forward, hit, 300)) {

			}
		}

When I have named all these variables (ray and hit), it tells me that I’m using Physics.raycast wrong.

ERROR MESSAGE: Assets/Custom Assets/Scripts/ShootGun.cs(19,36): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit, float, int)’ has some invalid arguments

I think you may have just messed up the types.
I would double check what types you declared “ray” and “hit” as and make sure you match one of the function overloads specified in the docs: Unity - Scripting API: Physics.Raycast

You need to put the out keyword before the RaycastHit parameter:
Physics.Raycast(ray, transform.forward, out hit, 300)

You also may be mixing the version that takes origin and direction as vectors with one that just takes a ray. They’re multiple versions so check the documentation

Found it:

Turns out that Camera.main.ScreenPointToRay(Screen.width / 2, Screen.height / 2, 0) makes transform.forward create panic in unity :confused: