Heres one. I use raycast for my guns so this should work.
if (Physics.Raycast (gunPos, direction, hit, bulletRange)) {
//Check if we hit something
if (hit.rigidbody){
// Apply a force to the rigidbody we hit
hit.rigidbody.AddForceAtPosition(bulletHitForce * direction, hit.point);
//Send a message to the hit object so its aware that is hit so it can take apropriate action
//like applying damage to itself
hit.collider.SendMessageUpwards("ApplyDamage", bulletDamage, SendMessageOptions.DontRequireReceiver);
//If show Gizmos is turned on you will be able to see a red line between the gun and the hit object
//this is for debugging purposes only
Debug.DrawLine(gunPos, hit.point,Color.red);
}
//Show spark where bullit hit
if(Smoke) //Check if the object exists
{
Smoke.transform.position = hit.point;
var rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
var Smoke: GameObject = Instantiate (Smoke, hit.point , rotation);
}
}
(Included other part of script inside my weapon script to show my placement)
Peace, Aaron Lewis
Note: You need a GameObject called smoke at the top of your script.