- Home /
Instantiating
Hello,
I am using Explosion Framework package. I am only using "Detonator - Tiny". I just imported it and its supporting assets from that package. Then I placed it on a random position on the screen to test it. It worked perfectly. Then I changed the name of the Prefab from "Detonator - Tiny" to "Detonator" as when I was trying to Instantiate it was giving me problems with '-' within it.
Then I just wanted to light up when my canon lands on the ground. Hence I disable the force and the rest of the physics components which would disturb other rigid bodies. Now again I tested it on an open space - it worked fine.
Code:
Now I have a script by the name "cannondestroy.js" wherein I destroy the canon on collision with the floor. The code goes as follows.
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "floor")
{
//Checks if floor is hit
var detonate = Instantiate (Detonator,gameObject.transform.position , Quaternion.identity);
Destroy(gameObject); //Destroys this gameObject if true.
}
}
Now I get this error :
No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list ' (System.Type.UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
Code Explanation:
Detonator - is a prefab
Destroy(gameObject);
I have attached the script to the Prefab which I have to destroy.
I would also like to note that, without the detonator attachment - it works.
Request:
I am not sure where I have gone wrong. I would have to humbly request you guys for a solution. All my aim is to create an explosion when the cannonball is destroyed. If you guys could give me an alternative too - I would be happy and appreciate it.
THANK you very much
Answer by Justin Warner · Dec 07, 2011 at 03:16 AM
var detonateObject : GameObject;
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "floor")
{
//Checks if floor is hit
var detonate = Instantiate (detonateObject,gameObject.transform.position , Quaternion.identity);
Destroy(gameObject); //Destroys this gameObject if true.
}
}
Try that, been a while sense I did this hah, but that might work. If not, comment back, I'll try to reply.