- Home /
major problems with getting my GUI Texture to fade out in bool function
I am having SERIOUS PROBLEMS getting this thing to work the way I want it to.
this code is placed on a empty gameobject called "EmptyObject"
Texture1 is a solid black texture; Texture2 is atransparernt black texture.
Texture1 is drawn over the screen when the game starts and should be triggered to fade out when a button is pressed. the function for that button is triggered in another script which I will call 'OTHERSCRIPT'.
when a button in OTHERSCRIPT is pressed it makes Time.timeScale = 0 and the texture is displayed again as Texture2
EDIT Texture1 is not fading out at all. I am using Time.time so bu the rime i'm ready to fade the value is too high but Time.deltaTime runs only once in the boolean function for some reason
here is the full code
using UnityEngine;
using System.Collections;
public class PauseEffectsandActions : MonoBehaviour {
public Texture2D theTexture;
public Texture2D Texture1;
public Texture2D Texture2;
private float StartTime;
void Awake()
{
theTexture = Texture1;
}
void OnLevelWasLoaded (){
StartTime = Time.time;
}
void OnGUI (){
if(GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT>().FirstDisplay == false)
{
Color newColor = GUI.color;
GUI.depth =10;
newColor = Color.white;
newColor.a = Mathf.Lerp(1.0f, 0.0f, (Time.time-StartTime));
GUI.color = newColor;
GUI.DrawTexture( new Rect( 0, 0, Screen.width,Screen.height ), theTexture);
}
if(GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT>().FirstDisplay == true)
{
GUI.DrawTexture( new Rect( 0, 0, Screen.width,Screen.height ), theTexture);
}
if(Time.timeScale == 0 && GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT>().FirstDisplay ==false)
{
theTexture = Texture2;
StartTime = Time.time;
GUI.depth =1;
}
}
}
Answer by Alanimator · Jan 18, 2014 at 05:44 PM
full code I used Time.deltaTime and made a few edits here and there
public Texture2D theTexture;
public Texture2D Texture1;
public Texture2D Texture2;
private float StartTime;
void Awake()
{
theTexture = Texture1;
}
void OnLevelWasLoaded (){
StartTime = 0.0f;
}
void OnGUI (){
GUI.depth =1;
if (GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT> ().FirstDisplay == false)
{
Color newColor = GUI.color;
newColor = Color.white;
newColor.a = Mathf.Lerp (1.0f, 0.0f, (StartTime += Time.deltaTime/4));
GUI.color = newColor;
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), theTexture);
}
if (GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT> ().FirstDisplay == true)
{
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), theTexture);
}
if(Time.timeScale == 0 && GameObject.Find ("GUI Area").GetComponent<OTHERSCRIPT>().FirstDisplay ==false)
{
theTexture = Texture2;
StartTime = 0;
}
}
Answer by MarkD · Jan 18, 2014 at 12:42 AM
I am a UnityScript scripter but on first sight your code seems fine. Also it is hard to answer if you don't discribe your problem, saying I am having major problems does not make it clear for us what exactly your problem is :).
Your answer
![](https://koobas.hobune.stream/wayback/20220613130729im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Display a texture fade? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Fade in AudioLister over time #c 1 Answer
Texture on plane not displaying properly 0 Answers