Hi Everyone,
I am writing a script to fadeout a GUITexture (and a few other things) after an input from the keyboard has been received. I am having trouble with decreasing the alpha value for the GUITexture slowly, at the moment the GUITexture fades out almost instantly. I have seen similiar questions on this topic and the solutions seems to be with using co-routines. I do not understand how to write coroutines in JS.
My fadeout function is similiar to Zerofractals fade function. I have also looked at Mathf.Lerp and mathf.SmoothDamp, however I could not achieve what I wanted. Perhaps I am using the functions incorrectly or not as intended. Any help on this would be much appreciated.My code is as follows
var scrollTexture:GUITexture;
var messageToGamePlayer: GUIText;
var scrollText: GUIText;
var fadeDuration:float = 0.5;
var alpha:int;
private var timeLeft:float=0.5;
function Start () {
scrollTexture.enabled=false;
messageToGamePlayer.enabled=false;
scrollText.enabled=false;
}
function OnTriggerEnter(){
this.renderer.enabled=false;
scrollTexture.enabled=true;
messageToGamePlayer.enabled=true;
scrollText.enabled=true;
}
function Update (){
if (Input.GetButton ("Jump")){
fadeOut();
// disableGUITexture();
// Destroy(gameObject);
}
}
function fadeOut(){
if(scrollTexture.color.a > 0){
timeLeft = timeLeft - Time.deltaTime;
alpha = (timeLeft/fadeDuration);
scrollTexture.color.a=alpha/2;
}
}
function disableGUITexture(){
scrollTexture.enabled=false;
messageToGamePlayer.enabled=false;
scrollText.enabled=false;
}
Thanks in Advance.