- Home /
Fade camera while teleporting
Hello all.
I'm working on some code that will fade the camera to black after hitting a button. While the camera is faded to black, I'm going to teleport it throughout my scene. I have this code that I found on another question about creating a fade for the camera:
alphaFadeValue = Mathf.Clamp01(alphaFadeValue - (Time.deltaTime / 5));
GUI.color = new Color(0, 0, 0, alphaFadeValue);
GUI.DrawTexture( new Rect(0, 0, Screen.width, Screen.height ), blackTexture );
but as of right now it is doing nothing. Its not directly in OnGUI, but it is in a function that is being called from OnGUI. Is there something wrong with the above code, or is there something wrong with my logic? Any help would be greatly appreciated.
Answer by Lo0NuhtiK · May 07, 2012 at 03:15 PM
Put the gui stuff in OnGUI , throw the alphaFade into another function and call it from update (or put it in update itself)
e.g.
bool fade = false ;
void Update(){
if(get a key down)
fade = true ;
if(fade)
FadeStuff() ;
}
void FadeStuff(){
alphaFade = mathfJunk ;
}
void OnGUI(){
GUI.color = whatever ;
GUI.DrawTextures = whateverElse ;
}
Thanks for the help. Breaking up the code like that did the job. Just a few tweaks I need to make here and there and I'll be good to go. Appreciate it!
Your answer
![](https://koobas.hobune.stream/wayback/20220613071216im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fade Out Camera 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Cinemachine freelook cam Crossplatform Input Movement 0 Answers