I’m making an FPS, right now I’m working on picking up guns on the floor. I got it to fully function by using the function “OnMouseEnter” and “OnMouseExit”, but I just used those for testing purposes, now I want a raycast from the camera and if the raycast hits a gun, it switches the weapon. I was looking at the scripting reference but I couldn’t find enough information on RayHit, or something like that. I already know how to cast a raycast, but I don’t know how to get information from it, so I need help with that. All I need to know is how to check if the raycast is with a gun. I’m using javascript. Thanks!
You need to use information from your camera when generating the raycast like:
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.rotation, 1000)) {
Debug.Log("Hit.");
}