trigger explosion on different object
if there is anything covering this I haven't found it. Plenty on how to blow up yourself, that is to say when the player enters a trigger that object explodes. though I don't want to blow my player up I want him to ALMOST get blown up by approaching a burning car but when he hits a trigger near the car the CAR blows up, NOT the stupid trigger. I imagine the code goes in the () in the statement " var expl = Instantiate(explosion, transform.position, Quaternion.identity);" replacing " transform.position, Quaternion.identity" with the name of the object "car"?. This is the simple explosion code to blow myself up. Can anyone tell me how to blow up something besides the actual trigger ( and myself)?
var explosion: GameObject;
var blowup: GameObject; // drag your explosion prefab here
function OnTriggerEnter(){
var expl = Instantiate(explosion, transform.position, Quaternion.identity);
Destroy(gameObject); // destroy the grenade
Destroy(expl, 3); // delete the explosion after 3 seconds
}
You would need a script on the explosion that's destroys it after time. You are destroying the gameObject that the script is running on and so the Destroy(expl, 3) never gets called;
Try this:
var explosion: GameObject; var blowup: GameObject; // drag your explosion prefab here
function OnTriggerEnter(){
var expl = Instantiate(explosion, transform.position, Quaternion.identity);
Invoke("Dest",3f);
Destroy(gameObject); // destroy the grenade
}
function Dest(){
Destroy(expl); // delete the explosion after 3 seconds
}
Your answer
Follow this Question
Related Questions
Fall down Cube object from platform. 0 Answers
function call inside OnClick Event? 1 Answer
Code is acting different depending on call 2 Answers
Hello I'm Sky, 1 Answer
Why nothing happens if a Box Collider enters a Trigger? 2 Answers