Instantiate facing away from GameObject face


I have the below script that passes the ray cast hit information to a GlobalVar.js

function Update () {
// Only continue if main camera
		var ray : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0));

		if (Physics.Raycast (ray, hit, 1000, myLayerMask)){
			globalVarsNetworkScript.rayCastHitTag = hit.collider.gameObject.tag;
			globalVarsNetworkScript.rayCastHitName =;
			globalVarsNetworkScript.rayCastTransform = hit.transform;
			globalVarsNetworkScript.rayCastHitPoint = hit.point;
			globalVarsNetworkScript.rayCastHitDistance = hit.distance;


Then in another script I’m trying to instantiate a prefab facing away from the GameObjects face where the ray cast hit, like a decal of a bullet hole, I thought this would do it but it does not work.

Instantiate(sparksPrefab, globalVarsNetworkScript.rayCastHitPoint, Quaternion.Euler(globalVarsNetworkScript.rayCastHitPoint.forward));

How would I do this please, Thanks.

You are going to need to pass the ‘normal’ from the ‘hit’ to this routine. Given the way you have thing structured, you will need to add a raycasthitNormal to the GlobalVar script and then add

 globalVarsNetworkScript.rayCastHitNormal = hit.normal;

Then the above code would use this for the rotation in the Instantiate: