Fade out Image Effects?

Hi! I was wondering if there is a possibility to fade out an image effect. Example: I have a script where the player gets his then this image effect will show up and then fade out after 2 or 4 seconds. BTW: I already have a script that shows a texture when the player gets damaged. I want to change it to an Image Effect, example: Grayscale Effect.

Is that possible? Thanks :smiley:

1 Answer

1

Best solution imho is using a GUITexture. Simply interpolate the alpha value of the GUITextures color property. Code could look like this(C# but js would work basically the same):

public GUITexture _myTexture;    //The guiTexture you want to manipulate. Set this up in the inspector.
public float stayTime = 2f;   // Time before fading starts
public float fadeTime = 2f;   // How long we want to fade
private float lastStartTime = -100f;

void Update(){
    if_myTexture.enabled == true) AnimateImage(); //Animate the texture if it is enabled
}
void AnimateImage(){
    float t = (Time.time - lastStartTime- stayTime)/fadeTime;
    if(t <= 1f){
        Color fullColor = Color.white;
        Color noColor = new Color(1f,1f,1f,0f);
        _myTexture.color = Color.Lerp(fullColor, noColor, t) ;
    } else {    //Once we faded out we shut the texture off, in order to save memory
        _myTexture.enabled = false;
    }
}
public void ShowImage(){    //Call this to start the effect
    _myTexture.enabled = true;
    lastStartTime = Time.time;
}

thanks! but forgot to mention that I already have the GUITexture showing up when the player takes damage. I wanted to change it to show an image effect, example the Grayscale Effect.

–

yup, I have the pro version of Unity. And I already have imported the pro assets in my game, and applied the grayscale effect onto the camera. Now I just want it to show when the player gets hurt and then fade away by time. I suppose you're supposed to use alpha? And btw, i dont want to use texture like blood splatter, its too original, get me? :P That's why I want to use the GrayScale Effect when the player gets hurt.

–

I think I finally get what you are trying to do. Unfortunately I don't have pro myself, so I can't really tell, but it seems you have to use [ColorCorrectionCurves][1]. Then you only need to manipulate the saturation. [1]: http://docs.unity3d.com/Documentation/Components/script-ColorCorrectionCurves.html

–

AH! YES! I GOT IT TO WORK! Thanks! Now I just gotta figure out on how to do it with NoiseGrain Effect ;P But thanks anyway! WORKED!

–