I have been using UnityScript for a basic loading screen and it has worked fine. I am getting better at C# now however and I am working on converting all of my scripts over. I have hit a snag though, and I think I know what is causing the problem but I’m not sure how to fix it. When it goes to the screen everything draws, it just shows a still image for the loading bar that previously worked in UnityScript. I THINK it is due to the fact that while parsing it throws errors if you don’t use (new Rect (vars, blah, blah)), however in UnityScript it is fine. I have pasted the UnityScript (working) one and the C# (not working) down below. I hope I was clear enough, thanks in advance.
UnityScript
#pragma strict
private var progress : float = 0;
private var height = Screen.height / 2 + 100;
private var heightLogo = Screen.height / 2 - 250;
private var isLoading : boolean = true;
var progressBarSize : Vector2 = new Vector2 (400, 40);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
var companyLogo : Texture2D;
var gameLogo : Texture2D;
var splashText : Texture2D;
var backgroundImage : Texture2D;
function Awake ()
{
Application.targetFrameRate = 60;
}
function Start ()
{
var menuSelect = Random.Range(1, 3);
yield WaitForSeconds (15);
isLoading = false;
yield WaitForSeconds (1);
Application.LoadLevel (menuSelect);
}
function OnGUI()
{
GUI.DrawTexture (Rect (0, 0, Screen.width, Screen.height), backgroundImage);
if (isLoading == true)
{
GUI.DrawTexture (Rect (Screen.width / 2 - 200, height, progressBarSize.x, progressBarSize.y), progressBarEmpty);
GUI.BeginGroup (new Rect (Screen.width / 2 - 200, height, progressBarSize.x * Mathf.Clamp01(progress), progressBarSize.y));
GUI.DrawTexture (new Rect (0, 0, progressBarSize.x, progressBarSize.y), progressBarFull);
GUI.EndGroup();
}
GUI.DrawTexture (Rect (Screen.width / 2 - 450, heightLogo, 256, 256), companyLogo);
GUI.DrawTexture (Rect (Screen.width / 2 + 200, heightLogo, 256, 256), gameLogo);
GUI.DrawTexture (Rect (Screen.width / 2 - 100, Screen.height /2 - 100, 200, 80), splashText);
}
function Update()
{
progress = Time.time * 0.07;
}
C#
using UnityEngine;
using System.Collections;
public class LoadScreen : MonoBehaviour
{
private float progress = 0;
private int height = Screen.height / 2 + 100;
private int heightLogo = Screen.height / 2 - 250;
private bool isLoading = true;
public Vector2 progressBarSize = new Vector2 (400, 40);
public Texture2D progressBarEmpty;
public Texture2D progressBarFull;
public Texture2D companyLogo;
public Texture2D gameLogo;
public Texture2D splashText;
public Texture2D backgroundImage;
void Awake ()
{
Application.targetFrameRate = 60;
}
void Start ()
{
StartCoroutine (WaitCoroutine ());
}
void OnGUI ()
{
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundImage);
if (isLoading == true)
{
GUI.DrawTexture (new Rect (Screen.width / 2 - 200, height, progressBarSize.x, progressBarSize.y), progressBarEmpty); // HERE IS WHAT I THINK THE ISSUE IS
GUI.BeginGroup (new Rect (Screen.width / 2 - 200, height, progressBarSize.x * Mathf.Clamp01(progress), progressBarSize.y));
GUI.DrawTexture (new Rect (0, 0, progressBarSize.x, progressBarSize.y), progressBarFull);
GUI.EndGroup();
}
GUI.DrawTexture (new Rect (Screen.width / 2 - 450, heightLogo, 256, 256), companyLogo);
GUI.DrawTexture (new Rect (Screen.width / 2 + 200, heightLogo, 256, 256), gameLogo);
GUI.DrawTexture (new Rect (Screen.width / 2 - 100, Screen.height /2 - 100, 200, 80), splashText);
}
void Update ()
{
}
IEnumerator WaitCoroutine()
{
int menuSelect = Random.Range(1, 3);
yield return new WaitForSeconds (15);
isLoading = false;
yield return new WaitForSeconds (1);
Application.LoadLevel (menuSelect);
yield break;
}
}