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(){
    trnsp = Shader.Find("Transparent/Diffuse");

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

function Destroyed(){
    if(explosion != null)

        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.



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


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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s