Hi everyone, i’ve got a problem with my damage receiver script.
- How to make all players, AI, and objects got hit / applied damage if they were in the TNT (TNT has explode all objects will affected by the explosion on certain range, i don’t know how to explain (Damage between range))
- How to make if the player / bullets touched the TNT, the TNT Starts counting down (Beeping fast) till 3 seconds then boom.
I attached my scripts here
thanks for the help!
enum ExplosionTypes {TNT, Nitro, Other}
var explosionType : ExplosionTypes;
var explosion : Transform;
var damage : float;
var hitPoints : float = 0;
var deadReplacement : Rigidbody;
var explosionFX : AudioClip;
private var explodeSecs : float = 1;
private var duration : float = 1;
private var isTNT = false;
function OnCollisionEnter (col : Collision){
var contact : ContactPoint = col.contacts[0];
var rot : Quaternion = Quaternion.FromToRotation(Vector3.up,contact.normal);
var pos : Vector3 = contact.point;
if(col.collider.gameObject.tag == "Player" || col.collider.gameObject.tag == "Bullets"){
if(explosionType == ExplosionTypes.Nitro){
Instantiate(explosion,pos,rot);
Explode();
audio.PlayOneShot(explosionFX);
Destroy(gameObject);
col.collider.SendMessage("ApplyDamage",damage,SendMessageOptions.DontRequireReceiver);
}
if(explosionType == ExplosionTypes.TNT){
isTNT = true;
}
if(explosionType == ExplosionTypes.Other){
Instantiate(explosion,pos,rot);
Explode();
audio.PlayOneShot(explosionFX);
Destroy(gameObject);
col.collider.SendMessage("ApplyDamage",damage,SendMessageOptions.DontRequireReceiver);
}
}
}
function Update () {
var t : float = Mathf.PingPong (Time.time, duration) / duration;
if(isTNT){
renderer.material.color = Color.Lerp(Color.red,Color.gray,t);
}
}
function Explode(){
var expl : Transform;
expl = Instantiate(explosion,transform.position, transform.rotation);
Destroy(gameObject);
if(isTNT) isTNT = false;
}
@script RequireComponent(AudioSource);