Dissolve object on Gameobject Destory

Hi, I’ve the dissolve>Diffuse shader from the Wiki by genericuser :|.

How to make a gameobject with a lot of function in his script dissolve when he destroy him or when the dialogue has finished playing ?
How to automate the slice amount cursor from 0 to 100 in 2 seconds and then destroy the object ?

Thanks by advance.

Here the script :

   #pragma strict
 
var CC : GameObject;
var CCBad : GameObject;
 public var pop : AudioClip;
 public var pop2 : AudioClip;
 public var dialogue : AudioClip;
 
function OnTriggerEnter (other : Collider) {
if (other.tag == "Player"){
CC.SetActive(true);
CCBad.SetActive (false);
 AudioSource.PlayClipAtPoint(pop, transform.position );
 AudioSource.PlayClipAtPoint(dialogue, transform.position );
}
}
 
function OnTriggerExit (other : Collider) {
if (other.tag == "Player"){
CC.SetActive(false);
CCBad.SetActive (true);
Destroy( this.gameObject );
AudioSource.PlayClipAtPoint(pop2, transform.position );
}
}

If I understood you correctly,my suggestion is that you can use a co-routine to do this.Loop until a value which is initially 100 gets reduced to zero and simoultaneously assign the value to the shader,Once the value reaches zero,exit the loop and perform post dissolve task like destroying the game object.

Here is the example code (not tested).Sorry my code is in C#

//The slice value to be assigned to the shader
float Val_Slice=100;    

void OnTriggerEnter (Collider other) 
{
  if (other.gameObject.tag == "Player")
  {
    CC.SetActive(true);
    CCBad.SetActive (false);
    AudioSource.PlayClipAtPoint(pop, transform.position );
    AudioSource.PlayClipAtPoint(dialogue, transform.position );
  }
}

void OnTriggerEnter(Collider other)
{
  if(other.gameObject.Tag=="Player")
  {
    //Start the FadeAndDestroy coroutine here
    StartCoroutine("FadeAndDestroy");
  }
}

IEnumerator FadeAndDestroy()
{
  //Loop until slice value reaches zero
  while(Val_Slice>0.0f)
  {
    //Reduce slice value over time
    Val_Slice-=Time.deltatime;

    //Apply the slice value to shader(change the string "_SliceAmount" to ur shader property string)
    renderer.material.SetFloat("_SliceAmount",Val_Slice);

    //Use this line if you want to increase the delay in decrementing
    //yield return new WaitForSeconds(0.1f);

  }

  //Loop exited since value reached zero (perform post dissolve task here)
  CC.SetActive(false);
  CCBad.SetActive(true);
  Destroy(this.gameObject);
  AudioSource.PlayClipAtPoint(pop2,transform.position);
}

}

Good Luck…