Raycast Shooting

Can Some1 maybe donate or explain to me how to make a raycast shooting script for an fps. i’m trying to replace my collision based one, it sucks.


Rough code outline to shoot a ray and delete any object it hits. This code will only hit objects with attached colliders. Within your game, you could do some detection to figure out what type of gameObject you hit and respond appropriately instead of just destroying it. You could figure out what kind of object you hit by looking at attached components, the objects name, or maintain a list of different types of objects in your seen and compare to see if it is one of them.

void Shoot(Vector3 gunPos, Vector3 gunDir) {
   RaycastHit hit;
   if (Physics.Raycast(gunPos, gunDir, out hit)) {