Instantiate explosion to Raycast.hit

Hello everyone, I’m new to unity scripting and I immediately encountered problem I could not solve alone. This is, in fact, my first script, so my understanding of scripting is shabby. I tried to use other similar scripts online as reference, but failed.
I’m trying to instantiate explosion made with Detonator to the position where ray from gun hits.

Error I’m getting is following: “Assets/assault rifle.js(13,12): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Vector3)’ was found.”

var explosionPrefab : GameObject;

function Update () {

if(Input.GetButtonDown(“Fire1”)) {

var hit : RaycastHit;
var gunRange : float = 10;

if(Physics.Raycast(transform.position, transform.forward, hit, gunRange)) {

Instantiate(explosionPrefab, hit.point, hit.normal);

}

}

}

maybe replace hit.normal to Quaternion.LookRotation(hit.normal);
The third param of the INstantiate is Quaternion, not Vector3, this is what the error log says

1 Like

Absolutely fantastic, works perfectly! Thank you very much, but I fear I will return many times in the future with tougher problems. : )