- Home /
Fading between scenes
Hi. So i have a scene, and want it to fade over to scene2.. I've used a 1x1 pixel, and stretched it to fill the screne. The idea was, to increase the opacity to create a fading effect. Right now, it stops fading half way.
This is my code for now.
public Texture2D Fade;
float alphaFadeValue = 0;
void OnGUI() {
GameObject badTrashCan = GameObject.Find("BadTrashCan");
sceneswapone sceneswapone = badTrashCan.GetComponent<sceneswapone>();
if(sceneswapone.timer < 2) {
alphaFadeValue += Time.deltaTime;
GUI.color = new Color(alphaFadeValue, alphaFadeValue, alphaFadeValue, alphaFadeValue);
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), Fade);
}
}
Comment
This question has been already answered, you should look for it in the already answered quesitons. I haven´t found it myself but I know it´s somewhere.
Answer by StormSabotage · Dec 10, 2013 at 02:52 PM
Maybe your condition
if(sceneswapone.timer < 2) {
returns FALSE earlier than ur alphaFadeValue becomes 1 ?
alphaFadeValue += Time.deltaTime;
btw: it's a bad way to assign GameObject to variable and take it's Component at runtime in OnGUI() like you do:
GameObject badTrashCan = GameObject.Find("BadTrashCan");
sceneswapone sceneswapone = badTrashCan.GetComponent<sceneswapone>();
if it's always same component of same gameobject it's much better assign it on Start()
private ScenesWapone sceneswapone;
void Start(){
sceneswapone = GameObject.Find("BadTrashCan").GetComponent<ScenesWapone>();
}