- Home /
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 :D
Answer by Lockstep · Apr 19, 2013 at 04:26 PM
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.
Grayscale effect, like all image effects is in the pro version only. In case you got it, just import the pro standard assets. Otherwise you are stuck with manipulating the color.
If your image only has one color (i.e. blood splatters or something), you can reimport it without color and then color it through the guitextures color property. You only need to change fullColor to Color.red (for blood)
edit: In this case you might want to make the fullColor a public varible and set it through the inspector for easier picking the right hue
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. Then you only need to manipulate the saturation.
AH! YES! I GOT IT TO WOR$$anonymous$$! Thanks! Now I just gotta figure out on how to do it with NoiseGrain Effect ;P But thanks anyway! WOR$$anonymous$$ED!
Your answer
Follow this Question
Related Questions
Collision Damage, Hit points and Instantiate 1 Answer
Robot Not Taking Damage 0 Answers
Health Regeneration 2 Answers
Floating damage text? 2 Answers
Detecting Raycast collision on an enemy to deal damage 1 Answer