- Home /
If health <5 Then Explode
Hello, im not a retard , but how to make car Explode when its Health is Lower than 5
using UnityEngine;
using System.Collections;
public class MasinosDuzimas : MonoBehaviour {
public Transform Sprogimas; //It means Explosion
public int Health = 100;
void Start () {
}
void Update () {
}
}
Thanks!
What does "explode" mean to you? In terms of triggering the explosion, you can do:
void Update () {
if (Health < 5) {
// Do something to make it explode
;
}
}
You can make it disappear with Destroy(gameObject);
to make burned car color just simply make a new material and use the same texture that is use for the car and change the color to black for the burned car.Please,tell me,what do you think
Answer by Auggie · Mar 18, 2013 at 12:57 AM
you need two things: 1. a "dead" car replacement prefab (something like a junk car that has a burnt texture or anything that looks like a damaged car with fire burning on it) 2. an explosion prefab
your code would be something like this:
using UnityEngine;
using System.Collections;
public class MasinosDuzimas : MonoBehaviour {
public Transform Sprogimas; //It means Explosion
public GameObject carReplacement; //substitute for the car
public int Health = 100;
void Start () {
}
void Update () {
if(Health < 5)
{
Instantiate (Sprogimas, transform.position, transform.rotation);
Instantiate (carReplacement, transform.position, transform.rotation); //this will be the damaged car
Destroy(gameObject); //this will remove the car from the game
}
}
}
i hope this helps...
Answer by Riebulka · Mar 23, 2013 at 06:23 PM
Thanks Youre Genius
i'm not really genius material...hehehe... but you're welcome
Your answer
![](https://koobas.hobune.stream/wayback/20220613094603im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Why doesn't my explosive barrel code work? 0 Answers
My player HP are get decreased from several GameObjects that has is Trigger on 0 Answers
OnCollisionEnter doesn't work: changing wheelcollider's sideway friction stiffness 0 Answers