- Home /
exploding a car
Hi
I am using the detonator kit from Unity. I am trying to make a car explode.
My question is that, the moment after I explode the car, how can I replace the car with a burned one?
Thanks.
Answer by flaviusxvii · Mar 22, 2011 at 06:31 PM
Destroy the car, Instantiate a burned car.
http://www.unifycommunity.com/wiki/index.php?title=OnCollideExplode
Answer by AngryOldMan · Mar 21, 2011 at 08:43 PM
var BurntPrefab : GameObject;
if (CarExploded == true) { Instantiate (BurntPrefab, transform.position, transform.rotation); }
Answer by efge · Mar 22, 2011 at 06:56 PM
Take a look at the reference: Instantiating Prefabs at runtime
Answer by Kashaunzilla · May 09, 2011 at 03:08 AM
Ok this is very simple to do actually. You need to place a life component on your car. Here is the script for that.
var hitPoints = 100;
var explodedCar = Transform;
function ApplyDamage (damage : float)
{
if (hitPoints <= 0)
{
return;
}
hitPoints -= damage;
if (hitPoints <= 0)
{
var car = Instantiate(explodedCar, GameObject.Find("EXCar1").transform.position, Quaternion.identity);
}
}
Ok here let me explain a little. The hitpoints is how much damage it has taken. Or life. So if you shoot it or throw a grenade or what ever and it reaches 0 then it explodes. So put it on the car, make sure there is a collider on it. Now create a empty gameObject and put it on the same position it is for the car. Rename it ExCar1, duplicate the script and rename the EXCar1 to EXCar2 anf make another gameObject called EXCar2. Now if you want, that that if you shoot it enoough times it will catch fire on the engine this is pretty easy as well. So create a new if statement under the instantiate part.
if ( hitPoints <= 30 )
{
var fire = Instantiate(FirePrefab, GameObject.Find(Fire1S).transform.position, Quaternion.identity;
}
Ok now this function checks if it only has 30 life left and then it will find a gameObject called Fire1S, The S stands for Spawn. Create a empty gameObject and name it Fire1S. Place it where the engine is. Also create a new variable called var FirePrefab : Transform; and the transform should be fire particles. This should work for you and make sure that your weapon can apply damage.
Your answer
Follow this Question
Related Questions
Unity Explosion Framework didn't work 0 Answers
space shooting: same exolosions 0 Answers
i want to add fire shot at enemy gun explosion 1 Answer
Explosion Elimination script 2 Answers
Detonator Explosion Framework Black squares around fireball 1 Answer