- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Ash-Bash32 · Mar 04, 2014 at 07:55 PM ·
timerloadlevelloading screen
How would I Implement a 5 seconds Delay into my Loading Screen for Unity Free
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]);
}
}
}
Comment
Answer by DRProductions · Mar 04, 2014 at 08:08 PM
Lol fake load screen? anyways Just put a yield WaitForSeconds(DelayTime) before you load your level.
Your answer
Follow this Question
Related Questions
Starting/Triggering events based on hover time 0 Answers
Animated Loading Screen Unity Indie 0 Answers
scene loader issue 0 Answers
How to load a level after 30 seconds? 3 Answers
Countdown timer reaches, if score higher than 1 load next level?? 2 Answers