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.
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.
var BurntPrefab : GameObject;
if (CarExploded == true)
{
Instantiate (BurntPrefab, transform.position, transform.rotation);
}
Take a look at the reference: Instantiating Prefabs at runtime
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.
Destroy the car, Instantiate a burned car.
http://www.unifycommunity.com/wiki/index.php?title=OnCollideExplode
insert in the cars existing script
– anon61858128