I will not make a full script for you, but I will point you in the right direction
For your main problem, you can use Raycasting. Use the gun as the origin for the ray and Mouse.Hit()
as the direction
These tutorials should give you an idea about raycasting
And there are youtube tutorials on Raycasting