x


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.

more ▼

asked Mar 21 '11 at 08:41 PM

Michael 20 gravatar image

Michael 20
32 14 15 16

(comments are locked)
10|3000 characters needed characters left

4 answers: sort newest

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.

more ▼

answered May 09 '11 at 03:08 AM

Kashaunzilla gravatar image

Kashaunzilla
34 17 19 28

(comments are locked)
10|3000 characters needed characters left

Take a look at the reference: Instantiating Prefabs at runtime

more ▼

answered Mar 22 '11 at 06:56 PM

efge gravatar image

efge
5.1k 5 14 38

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Mar 22 '11 at 06:31 PM

flaviusxvii gravatar image

flaviusxvii
3k 13 19 43

(comments are locked)
10|3000 characters needed characters left
var BurntPrefab : GameObject;

if (CarExploded == true)
{
   Instantiate (BurntPrefab, transform.position, transform.rotation);
}
more ▼

answered Mar 21 '11 at 08:43 PM

AngryOldMan gravatar image

AngryOldMan
2.5k 12 21 47

I attach this to the car or to the detonator?

Mar 21 '11 at 08:49 PM Michael 20

insert in the cars existing script

Mar 21 '11 at 09:20 PM AngryOldMan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x417
x161
x151
x53

asked: Mar 21 '11 at 08:41 PM

Seen: 1010 times

Last Updated: Mar 21 '11 at 08:41 PM