- Home /
Fade Out Camera
This should be basic right? Put a texture in front of the camera and make the alpha lerp, move towards, whatever to 0. Well, this code:
Texture2D theTexture;
void OnGUI (){
GUI.color.a = Mathf.Lerp(0.0f, 1.0f, (Time.time / 2));
GUI.DrawTexture( new Rect(0,0,Screen.width, Screen.height), theTexture);
}
produces this error:
error CS1612: Cannot modify a value type return value of `UnityEngine.GUI.color'. Consider storing the value in a temporary variable
I understand this would work in javascript, but C# makes GUI.color read only, how would I go about this?
Thanks in advanced.
Answer by Yanger_xy · Sep 23, 2014 at 02:24 AM
The problem is here: GUI.color.a = Mathf.Lerp(0.0f, 1.0f, (Time.time / 2)); You can not set GUI.color value seperately, you should set its value like this:
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0) GUI.color = Mathf.Lerp(GUI.color, new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1), (Time.time/2));
Gotcha, I can't do individual variables of the color, I have to do all of them. Thanks!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Fade camera while teleporting 1 Answer
Multiple Cars not working 1 Answer
Fading To New Scene Problem? 1 Answer