imagination XD

realizing dream

[Legacy] Timed Object Destroyer

Leave a comment

I usually use this script to fade out and delete any object.

#pragma strict

var lifeTime = 3.0;
var fadeable = true;
var fadeableDur = 2.5;
var explosion : Transform;
var destroyParent  = false;
var arrayMaterials  = false;
private var trnsp : Shader;

function Awake(){
    Destroyed();
    trnsp = Shader.Find("Transparent/Diffuse");
}

function Update(){
    if(fadeable){
        renderer.material.shader = trnsp;
        renderer.material.color.a -= Time.deltaTime / fadeableDur;
        if(arrayMaterials){ //Not Tested.
            for(var i = 0; i < transform.childCount; i++){
                transform.GetChild(i).renderer.
material.color.a -= Time.deltaTime / fadeableDur;
            }
        }
    }
}

function Destroyed(){
    if(explosion != null)
Instantiate(explosion,transform.position,transform.rotation);

    if(destroyParent){
        if(transform.parent != null) 
Destroy(transform.parent.gameObject, lifeTime);
        else Destroy(gameObject, lifeTime);
    }else Destroy (gameObject, lifeTime);
}

To use this script, attach this script to dead replacement object (something like ragdoll prefab). I’m still working on the array materials function. Which mean you must attach it to some object that has renderer on it.

Advertisements

Author: IMGVERTEX

Started making games since 13 year old. 3D CGI Weeaboo | VFX Otaku | Anime Researcher | Indie Game Dev | VR Chuunibyou

FEED ME

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s