I'm using a slightly changed script I found hereabouts that fades the alpha of a texture and then destroys the script after it's done. I'm getting a runtime error "MissingMethodException: Cannot find method Destroy," however. Can anyone spot the mistake? Code (csharp): var initialDelay = 1.0; var fadeSpeed = 1.0; private var originalColor; originalColor = renderer.material.color; renderer.material.color.a = 0.0; yield new WaitForSeconds(initialDelay); while (renderer.material.color.a < originalColor.a) { Debug.Log("Fading. Alpha = " + renderer.material.color.a); renderer.material.color = Color.Lerp(renderer.material.color, originalColor, fadeSpeed * Time.deltaTime); yield; } Object.Destroy();
Ah, but I don't want to destroy the gameObject the script is attached to, just the script Component. I'll be editing the alpha of the texture later and I don't want this script getting in the way.
Then instead of passing the gameObject to Destroy, pass the component instead: Code (csharp): Destroy(this);
Sorry, skimmed it and didn't see the part about destroying the script. Destroy(this); http://unity3d.com/Documentation/ScriptReference/Object.Destroy.html -Jon