I’ve messed up Zerofractal’s FadeIn script. Obviously I don’t understand the boolean functions…I’m hoping someone here can help straighten me out.
What I want to happen is when the “Jump” button is pressed two things happen 1) The GUITexture fades up (which it does) and 2) The MouseLook script for the camera is disabled (which it does). Unfortunately, when the “Jump” button is released, the GUITexture fades out like it’s supposed to, but MouseLook doesn’t turn back on. Here’s my code:
var buttonName="Jump";
var fadeDuration:float=0.5;
var initialDelay:float=5;
private var timeLeft:float=0.5;
function Awake () {
timeLeft = fadeDuration;
}
function Update () {
if (initialDelay > 0){
initialDelay = initialDelay-Time.deltaTime;
} else {
if (Input.GetButton (buttonName))
fade(true);
else
fade(false);
}
}
function fade(direction:boolean){
var alpha;
if (direction){
if (guiElement.color.a < 0.5){
timeLeft = timeLeft - Time.deltaTime;
alpha = (timeLeft/fadeDuration);
guiElement.color.a=0.5-(alpha/2);
var go = GameObject.Find("MainCameraParentGameObject");
go.GetComponent("MouseLook").enabled = false;
} else {
timeLeft = fadeDuration;
}
} else {
if (guiElement.color.a > 0){
timeLeft = timeLeft - Time.deltaTime;
alpha = (timeLeft/fadeDuration);
guiElement.color.a=alpha/2;
} else {
timeLeft = fadeDuration;
}
}
}