I have a problem with a script that should run the Fade In and Fade Out between the start and the end of the scene.
The script is this:
using UnityEngine;
using System.Collections;
public class Fade_Screen_Scene : MonoBehaviour
{
public float fadeSpeed = 5.0F;
public GUITexture blackScreen;
private bool sceneStarting = true;
void Awake()
{
blackScreen.pixelInset = new Rect (0f, 0f, Screen.width, Screen.height);
}
void Update()
{
if (sceneStarting == true)
{
StartScene();
}
}
void FadeToClear()
{
blackScreen.color = Color.Lerp(blackScreen.color, Color.clear, fadeSpeed * Time.deltaTime);
}
void FadeToBlack()
{
blackScreen.color = Color.Lerp(blackScreen.color, Color.black, fadeSpeed * Time.deltaTime);
}
void StartScene()
{
FadeToClear();
if (blackScreen.color.a == 0.0f)
{
blackScreen.color = Color.clear;
blackScreen.enabled = false;
sceneStarting = false;
}
}
public void EndScene()
{
blackScreen.enabled = true;
FadeToBlack();
}
}
This script is put in a game object with a GUI Texture component
When the scene starts, a custom texture (in this case a black screen) Fade In, from black to clear. But when I press a trigger that enables the end of the scene, and calls the public void EndScene (), the texture DON’T Fade Out.
I don’t understand why and I tried so much. Please help me.
Okay, so you might want to manually center the mouse when the game starts. The Input class has a static function that allows you to set the mouse position.
– FortisVenaliter