ah, I should have better worded my vague question…
so, what I have set up right now is a basic menu system, if the user clicks a GUI button it adds the associated country to the countryList variable. Once countryList.count > 0 an additional GUI button shows which allows the user to accept or cancel their selected choice (this is what countryList is controlling). If the user selects ‘accept’ then the mainCamera FOV will be reduced, once the mainCamera’s FOV falls below a set number the selected scene (or scene defined by the countryList var) is to load.
Currently this works, but again when using the foreach function it’s delayed. I think it’s because it’s caught in a loop / calculation? You can see the FOV continue to reduce although significanlty reduced in FPS (as expected) when code is locked up. It will eventually load however, this takes about 10 seconds. If I just replace the foreach function with a basic Application.loadLevel function it works fine. But then I don’t have access to the data portion that i did with the foreach and I no longer know how to call the needed data to load my scenes…
Here’s the full code, sorry it’s still a bit unorganized, work in progress lol…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class gameManager : MonoBehaviour
{
//VARIABLES
//Bools
bool mainMenuHome;
bool Continue;
bool exit;
bool looper;
bool newGame;
bool waiting;
bool options;
bool pause;
//Cameras
public Camera mainCam;
public Camera countrySelection;
//Floats
//Common
float countrySelected;
float countrySelectedRoll;
float waitTimeCur;
//GUI
//GUI Aspect Ratio
float xAxis_GUI;
float yAxis_GUI;
//GUI Texture
float alpha = 1; //Alpha Color variable
float fadeColorREF;
//GameObjects
public GameObject countryCam;
//GUI Textures
public GUITexture fadeColor;
//Lists
List<string> countryList = new List<string>();
List<string> menuBtnList = new List<string>();
//FUNCTIONS
void Awake()
{
//Configure 'menuBtnList' default point
if(Application.loadedLevelName == "mainMenu")
{
mainMenuHome = true;
menuBtnList.Add ("newGame");
menuBtnList.Add ("Continue");
menuBtnList.Add ("options");
menuBtnList.Add ("exit");
}
}
void Update()
{
//Load Level
if(mainCam.fieldOfView <= 10)
{
foreach(string data in countryList)
{
Application.LoadLevel (data);
}
}
//Camera FOV correction
countrySelection.fieldOfView = mainCam.fieldOfView;
//On Input
//Keyboard Input
if(Input.GetKeyUp(KeyCode.UpArrow) !waiting)
{
countrySelectedRoll += 1;
}
if(Input.GetKeyUp(KeyCode.DownArrow) !waiting)
{
countrySelectedRoll -= 1;
}
//'countrySelected' function
//mainCam FOV
if(countrySelected > 0)
{
mainCam.fieldOfView = Mathf.Lerp (mainCam.fieldOfView, 20, Time.smoothDeltaTime / 5);
}
else
{
mainCam.fieldOfView = Mathf.Lerp (mainCam.fieldOfView, 30, Time.smoothDeltaTime);
}
//Main Camera Functionality
if(looper == true)
{
mainCam.fieldOfView = Mathf.Lerp (mainCam.fieldOfView, 1, Time.smoothDeltaTime);
if(mainCam.fieldOfView <= 1)
looper = false;
}
//GUI Texture alpha control
if(mainCam.fieldOfView > 30)
{
alpha = Mathf.Lerp (alpha, 1, Time.smoothDeltaTime); //Set Alpha to 'max'
fadeColorREF = Mathf.Lerp (fadeColorREF, 0, Time.smoothDeltaTime); //Set fadeColorRef to 'Black'
fadeColor.color = new Color (fadeColorREF,fadeColorREF,fadeColorREF, alpha);
}
if(mainCam.fieldOfView <= 30 mainCam.fieldOfView > 15)
{
alpha = Mathf.Lerp (alpha, 0, Time.smoothDeltaTime); //Set Alpha to 'max'
fadeColorREF = Mathf.Lerp (fadeColorREF, 1, Time.smoothDeltaTime); //Set fadeColorRef to 'White'
fadeColor.color = new Color (fadeColorREF,fadeColorREF,fadeColorREF, alpha);
}
if(mainCam.fieldOfView <= 15)
{
alpha = Mathf.Lerp (alpha, 1, Time.smoothDeltaTime); //Set Alpha to 'max'
fadeColor.color = new Color (fadeColorREF,fadeColorREF,fadeColorREF, alpha);
}
if(countrySelected == 1)
{
countryList.Add ("Africa");
waiting = true;
}
if(countrySelected == 2)
{
countryList.Add ("Australia");
waiting = true;
}
if(countrySelected == 3)
{
countryList.Add ("South America");
waiting = true;
}
if(countrySelected == 4)
{
countryList.Add ("United States");
waiting = true;
}
//'waiting' function
if(waiting)
{
waitTimeCur += Time.smoothDeltaTime; //Increase 'waitTimeCur' float.
}
//Main Camera Rotation Control
if(countryList.Count > 0)
{
if(countryList.Contains("Africa"))
countryCam.transform.localEulerAngles = new Vector3
(
Mathf.LerpAngle(countryCam.transform.localEulerAngles.x, 0, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.y, 0, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.z, 72, waitTimeCur)
);
if(countryList.Contains("Australia"))
countryCam.transform.localEulerAngles = new Vector3
(
Mathf.LerpAngle(countryCam.transform.localEulerAngles.x, 340, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.y, 18, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.z, 315, waitTimeCur)
);
if(countryList.Contains("South America"))
countryCam.transform.localEulerAngles = new Vector3
(
Mathf.LerpAngle(countryCam.transform.localEulerAngles.x, 0, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.y, 0, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.z, 160, waitTimeCur)
);
if(countryList.Contains("United States"))
countryCam.transform.localEulerAngles = new Vector3
(
Mathf.LerpAngle(countryCam.transform.localEulerAngles.x, 320, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.y, 352, waitTimeCur),
Mathf.LerpAngle(countryCam.transform.localEulerAngles.z, 190, waitTimeCur)
);
}
else
{
//InHouse Variables
//Floats
float zAxis = countryCam.transform.localEulerAngles.z;
//Float Control
zAxis -= Time.smoothDeltaTime;
//Release Camera Lock ((Retrun to basic rotation))
countryCam.transform.localEulerAngles = new Vector3
(
countryCam.transform.localEulerAngles.x, countryCam.transform.localEulerAngles.y,zAxis
);
}
}
void OnGUI()
{
if(Application.loadedLevelName == "mainMenu")
{
//Main Menu Background
GUI.Box (new Rect(Screen.width/2 - 125, Screen.height/2 - 125, 250, 250),""); //Main Menu Background
}
//Button Layouts
if(mainMenuHome)
{
//Main Menu
//New Game
if(GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height/2 - 25, 100, 25), "New Game"))
{
newGame = true;
mainMenuHome = false;
}
//Continue
if(GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height/2 - 50, 100, 25), "Continue"))
{
Continue = true;
mainMenuHome = false;
}
//Options
if(GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height/2, 100, 25), "Options"))
{
options = true;
mainMenuHome = false;
}
//Exit
if(GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height/2 + 25, 100, 25), "Exit"))
{
exit = true;
mainMenuHome = false;
}
}
if(newGame)
{
//'countrySelected' function
//Variable Countrol
if(countrySelectedRoll > countryList.Count || countrySelectedRoll < 1)
{
countrySelectedRoll = 1;
}
//Next Country
if(GUI.Button (new Rect(Screen.width/2 - 50, Screen.height/2, 100, 25), "Next"))
{
countrySelected = countrySelectedRoll;
countrySelectedRoll += 1;
}
//Previous Country
if(GUI.Button (new Rect(Screen.width/2 - 50, Screen.height/2 + 25, 100, 25), "Previous"))
{
countrySelected = countrySelectedRoll;
countrySelectedRoll -= 1;
}
//Africa
if(GUI.Button (new Rect(Screen.width/2, Screen.height/2 - 100, 100, 50), "Africa"))
{
countrySelected = 1;
}
//Australia
if(GUI.Button (new Rect(Screen.width/2 - 100, Screen.height/2 - 50, 100, 50), "Australia"))
{
countrySelected = 2;
}
//South America
if(GUI.Button (new Rect(Screen.width/2, Screen.height/2 + 50, 50, 50), "South America"))
{
countrySelected = 3;
}
//United States
if(GUI.Button (new Rect(Screen.width/2 - 100, Screen.height/2, 50, 50), "United States"))
{
countrySelected = 4;
}
//Are You Sure?
if(countryList.Count > 0)
{
if(GUI.Button (new Rect(Screen.width/2, Screen.height/2 - 50, 50, 50), "Yes"))
{
looper = true;
}
if(GUI.Button (new Rect(Screen.width/2 + 50, Screen.height/2 - 50, 50, 50), "No"))
{
looper = false;
countryList.Clear();
waiting = false;
waitTimeCur = 0;
countrySelected = 0;
mainCam.fieldOfView = Mathf.Lerp (mainCam.fieldOfView, 30, Time.smoothDeltaTime);
}
}
}
if(Continue)
{
//Application.LoadLevel("");
}
if(options)
{
//Show Options Menu
}
if(exit)
{
//Display 'ARE YOU SURE'
//Then
Application.Quit();
}
//Pause Menu
if(!pause)
{
GUI.Button (new Rect(Screen.width - 75, Screen.height - Screen.height + 25, 50, 50), "Pause");
}
}
}