Well, you probably don't want to dissolve/destroy your object in every single **Update** frame. Since the **Update** function wants to more or less perform all of its code in the same frame, it won't wait till the dissolve is finished to destroy the object, creating troubles and/or crashes. That's why you can't use a yield statement in an **Update** function. Instead, you might be better off placing the code you need in a separate function then calling it when you need it... like so:
function DissolveAndDestroy () {
// Do your dissolve thing
renderer.material.SetFloat( "_SliceAmount", 0.4f * Mathf.Abs(Mathf.Sin(Time.time)*0.6 ));
// Wait till it's finished dissolving
yield WaitForSeconds (The AmountOfTimeDissovleTakes);
// Destroy it
Destroy (gameObject, 1.5);
}
I didn't test ny of this, but it should give you the basic outline of how to get it working....
↧