Ive got code here that works as a basic loading Screen but I’m look to put a time delay on my version of code but i don’t know how to implement it. I want my loading screen to stay on screen for at least 5 extra seconds because when i load some scenes the loading screen goes on and off the second with in a flash.
using UnityEngine;
using System.Collections;
public class LoadingScreen : MonoBehaviour {
//A Check for if its loading.
private bool loading = true;
//For GUI Section
public Texture loadingTexture;
public Texture[] gunTextures;
//Font Style also for GUI Section
public GUIStyle fontStyle;
// For GUI Section
public int keyframePointer = 0;
public int keyframePointer1 = 0;
public int keyframePointer2 = 0;
//For Time Delay in seconds
public float delay = 5.0f;
void Awake () {
DontDestroyOnLoad(gameObject);
}
void Update () {
if(Application.isLoadingLevel){
loading = true;
keyframePointer = Random.Range(0, 112);
keyframePointer1 = Random.Range(0, 112);
keyframePointer2 = Random.Range(0, 112);
}
else{
loading = false;
}
//keyframePointer = Random.Range(0, 60);
Debug.Log(keyframePointer);
}
void OnGUI () {
if(loading){
float halfHeight = gunTextures[keyframePointer].height;
float halfHeight1 = gunTextures[keyframePointer1].height / 2;
float halfHeight2 = gunTextures[keyframePointer2].height / 2;
GUI.DrawTexture(new Rect(0,0,Screen.width + 4,Screen.height + 4), loadingTexture);
GUI.Label(new Rect(Screen.width - 340, Screen.height - 68, 300, 34), "Loading...", fontStyle);
GUI.DrawTexture(new Rect(Screen.width / 2 - 128, Screen.height / 2 - halfHeight1, gunTextures[keyframePointer1].width, gunTextures[keyframePointer1].height), gunTextures[keyframePointer1]);
GUI.DrawTexture(new Rect(Screen.width / 2 - 32, Screen.height / 2 - halfHeight, gunTextures[keyframePointer].width * 2, gunTextures[keyframePointer].height * 2), gunTextures[keyframePointer]);
GUI.DrawTexture(new Rect(Screen.width / 2 + 96, Screen.height / 2 - halfHeight2, gunTextures[keyframePointer2].width, gunTextures[keyframePointer2].height), gunTextures[keyframePointer2]);
}
}
}