- Home /
Temporary GUI image help?
Hi. I have made a simple image logo for my game I am making in Unity 3D.
Basically, I am a beginner in Unity, and I am trying to find a way to display a image on part of the screen, for like 5 seconds, then fade out.
May anyone help me, please?
Thanks.
-Hedgoeg
Answer by aldonaletto · Dec 21, 2012 at 01:58 AM
Select the desired texture in the Project view, then press the button Create in the Hierarchy view and select GUITexture: a GUITexture with your image will be created. Add the following script to it:
var alpha: float = 6; // 5 seconds + 1 second fade out
function Update () {
alpha -= Time.deltaTime; // decrement timer
guiTexture.color.a = Mathf.Clamp01(alpha); // set GUI alpha
if (alpha < 0) Destroy(gameObject); // suicides when totally invisible
}
The variable alpha starts with the value 6, and is decremented each frame. It's value clamped to the 0..1 range is assigned to the GUI alpha, thus when it's becoming lower than 1 the image starts to vanish. When alpha gets lower than zero, the image is completely invisible and is destroyed.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
open a link inside unity 2 Answers
Unity is acting REALLY weird 0 Answers
Adding a SDK to my game 0 Answers