[SOLVED]Unity Screen Fader Problem

Hi,
I am trying to make a between scene fader. It works fine in the Editor and Game mode, but it doesnt work on some computers. The scene stays black when loaded.

My setup is:

I put an UI Image and change the alpha value.

Here is my script:

using UnityEngine;
using System.Collections;

public class fading : MonoBehaviour {

    public Texture2D texture;
    public float fadeSpeed = 0.8f;
    public player p;
    public UnityEngine.UI.Image t;
    int drawDepth = -1000;
    float alpha = 1.0f;
    int fadeDir = -1;


    void Update(){
        fade ();
    }
    void fade(){
        alpha += fadeDir * fadeSpeed + Time.deltaTime;
        alpha = Mathf.Clamp01 (alpha);
        t.color = new Color(t.color.r, t.color.b, t.color.g, alpha);
    }

    public float BeginFade(int direction){
        fadeDir = direction;
        return (fadeSpeed);
    }

    void OnLevelWasLoaded(){
        //Debug.Log ("ABC");
        BeginFade (-1);
        Cursor.visible = false;
    }
}

THANKS :slight_smile:

so whats the difference between the ones where it does work and the ones where it doesn’t?

The Screen stays black when it doesnt work.

The Screen fades nicely when it works

On the PCs where it isn’t working, have you debug.logged the fade routine to see if it’s running and also setting the colour values you’d expect?

Try changing line 19 to:

alpha += fadeDir * fadeSpeed * Time.deltaTime;

Time.deltaTime should be multiplied else it may be fading at varying speeds on the different PCs

OH MY GOD, Thanks A LOT.

*Feeling embarassed… :sweat_smile: