instantiating prefab at object center not at hit point

simple script below I want to put on various objects and instantiate bullet hits according to the material/texture on that object. It works in that the test object knows it’s being hit and IS instantiating the prefab but it is doing so at the objects center rather than where I shot it.
I tried altering the gun script to add the variables there but…I got the script in the store and got as far as making a bullet hole spawn as a blood splat instead when I hit things tagged “enemy”. but I can’t seem to add more variables without breaking the script. So hoping I could put the script on the objects I shoot at. I can tell by the simple code that instantiating at the objects center would be the result, but this is my only attempt that even got THAT much to happen. Been searching all day and trying various “solutions” but they all seem to be tailored to the posters specific needs which aren’t the same

using UnityEngine;
using System.Collections;

public class hitByRay : MonoBehaviour {
	public GameObject prefab;
	void Start(){

	}
	void HitByRay () {
		Debug.Log ("yippee! you shot me");

		Instantiate(prefab, transform.position , transform.rotation);
	}
}

First of all Instantiate(prefab, transform.position , transform.rotation); instantiates the object at the center of the object that the script is attached to, because transform.position is the position of the transform of the object.

Anyway, thing is the solution I’d offer is, inside of your weapon script (where you are doing Physics.Raycast is presume), have a Vector3 that would hold the direction of the Ray and that’s mostly it.

Now, Physics.Raycast has an option to return a struct called RaycastHit, where it stores some information about the object that it hit and where it hit it.

Vector3 raycastDirection;
RaycastHit hitInfo;
(Physics.Raycast(Vector3 origin, raycastDirection, out hitInfo, maxDistance, layerMask)){
    // At this point, if the Raycast hit something that you wanted it to hit, it would have already sent out the information to the hitInfo struct.
    // That struct holds several great things
    // The point that the ray hit the other object: hitInfo.point
    // Knowing this information, you can instantiate the "bulletHole" prefab at that point and parent it to the object that it hit.
    GameObject bulletHole = (GameObject)Instantiate(bulletHolePrefab, hitInfo.point, Quaternion.identity);
    bulletHole.transform.SetParent(hitInfo.transform);
}

At this point, you might want to tweak the rotation of it a bit, but generally, what that script would do:
If you hit an enemy, instantiate a bulletHole prefab at that position that the raycast hit and parent it to that object.

If it’s not clear, I can elaborate on all this.

I know that the code SHOULD be in the weapon script because that is where the code is where can already instantiate bullet holes or bloodplatter if I hit people. The problem is that I can not add anything else to my weapon script without breaking it it seems. As stated originally , I bought the scripts in the store. It came with a weaponEditor script as well as the weapon script, and I copied the weapon script to make another weaponAim script ( for when looking down the sights) THIS script is where I was able to insert my bloodsplat. but NOT in the weapon script or weaponEditor script. In otherwords…it’s way over my head. Not even sure how I got the bloodsplatter to work and why I CAN"T get it to work in the Weapon script - weaponAIm and weapon script are IDENTICAL all I do is tweak the variables in the inspector to effect bullet accuracy but in the inspector view the scripts variable fields aren’t the sameBut, here is the weaponAim script if you can see where to SUCCESSFULLY add more instantaitions let me know please

using UnityEngine;
using System.Collections;

public class WeaponAim : MonoBehaviour {


	public Transform muzzlePoint;
	public GameObject bulletHolePrefab, muzzleFlashPrefab;
	public AudioClip fireSound;
	public bool shouldWeaponFire, semiAutoFire;
	public float spread = 0.05f;
	public float minSpread = 0.01f;
	public float maxSpread = 0.5f;
	public float maxBulletDist = 100.0f;
	public float fireDelay = 0.15f;
	public float bulletForce = 2000.0f;
	public GameObject bloodsplatPreFab;

	private float fireTimer;
	

	void Start () {
		Initialize ();
	
	}
	
	void Initialize () {
		NullErrorCheck ();
	}
	

	void NullErrorCheck () {
		if (!muzzlePoint) {
			Debug.LogError("Please make sure to set the muzzle point for your weapon!");
			Debug.Break ();
		}
		if (!bulletHolePrefab) {
			Debug.LogError("Please make sure to set the bullet hole prefab for your weapon!");
			Debug.Break ();
		}
		if (!muzzleFlashPrefab) {
			Debug.LogError("Please make sure to set the muzzle flash prefab for your weapon!");
			Debug.Break ();
		}
		if (!fireSound) {
			Debug.LogError("Please make sure to set the fire soound for your weapon!");
			Debug.Break ();
		}
		if (!shouldWeaponFire) {
			Debug.LogWarning("Your weapon will not be able to fire, make sure this is what you want!");
		}
	}
	

	void LateUpdate () {
		if (!muzzlePoint)
			return;
		
	
		if(Input.GetKeyDown(KeyCode.X)) {
			semiAutoFire = !semiAutoFire;
		}
		
		/* Checks to make sure you can fire the weapon and that the game
		 * is not paused */
		if(shouldWeaponFire && Time.timeScale > 0.0f)
			WeaponFire ();
		
	}
	
	/* This is what controls the different fire modes for semi, or
	 * automatic */
	void WeaponFire() {
		if(semiAutoFire && Input.GetMouseButtonDown(0)) {
			Fire();
		} else
		if(!semiAutoFire && Input.GetMouseButton(0)) {
			Fire();
		}
	}
	
	/* This is where we fire our weapon and play our muzzleflash, bullet
	 * effects, and sound */
	void Fire() {
		if (!bulletHolePrefab || !muzzleFlashPrefab || !fireSound)
			return;
		
		/* Controls the rate of fire */
		if(Time.time >= fireTimer) {
			audio.PlayOneShot(fireSound);
			
			GameObject mf = Instantiate(muzzleFlashPrefab, muzzlePoint.position, muzzlePoint.rotation) as GameObject;
			mf.transform.parent = muzzlePoint;
			
			/* Calls our function to spawn the bullet */
			SpawnBullethole();
			
			fireTimer = Time.time + fireDelay;
		}
	}
	
	/* This is where we spawn our bullet hole, give our cast
	 * weapon spread, and add force to any hit rigidbodies */
	void SpawnBullethole() {
		RaycastHit hit;
		Vector3 fwd = muzzlePoint.TransformDirection(Vector3.forward);
	//	Debug.DrawRay (transform.position, fwd, Color.green);
		if(Physics.Raycast(muzzlePoint.position, fwd, out hit, maxBulletDist)) {
			
			Vector3 tmpLoc = muzzlePoint.position;
			hit.transform.SendMessage ("HitByRay");
			Debug.DrawRay (transform.position, fwd, Color.green);

		
			if(Physics.Raycast(tmpLoc, fwd, out hit)) {
				GameObject bs = Instantiate(bulletHolePrefab, hit.point + (hit.normal * 0.01f), Quaternion.LookRotation(hit.normal)) as GameObject;
				bs.transform.parent = hit.transform;

				if(hit.rigidbody && !hit.rigidbody.isKinematic) {
					hit.rigidbody.AddForce(muzzlePoint.forward * bulletForce);

			if(hit.transform.gameObject.tag == ("enemy"))
					if(Physics.Raycast(tmpLoc, fwd, out hit)) {
						GameObject bh = Instantiate(bloodsplatPreFab, hit.point + (hit.normal * 0.01f), Quaternion.LookRotation(hit.normal)) as GameObject;
						bh.transform.parent = hit.transform;

						if(hit.transform.gameObject.tag == ("wall"))
						if(Physics.Raycast(tmpLoc, fwd, out hit)) {
							GameObject br = Instantiate(bulletHolePrefab, hit.point + (hit.normal * 0.01f), Quaternion.LookRotation(hit.normal)) as GameObject;
							br.transform.parent = hit.transform;



				
			float spreadMod = hit.distance * spread;
			
			spreadMod = Mathf.Clamp(spreadMod, minSpread, maxSpread);
			
			tmpLoc.x += Random.Range(-spreadMod, spreadMod);
			tmpLoc.y += Random.Range(-spreadMod, spreadMod);
			tmpLoc.z += Random.Range(-spreadMod, spreadMod);
			
			
				

				}
			}
		}
	}
}
}
}