- Home /
Loading multiplescenes additive
Hi everyone,
I've been reading a lot about this, but still can't figure it out.
I'm trying to do a platformer. I made a GameController that controls well... the Game.
The thing is this, I made a UI scene which is call when a new level is loaded (additive of course). After the loading of this scene, the Game Controller is supposed to link the lifeBar in the UI with the Player's healt.
This is the script that controls Level Loading:
private HUDController myHUDController;
void Start ()
{
DontDestroyOnLoad (this.transform.gameObject);
myHUDController = this.GetComponent<HUDController>();
}
public void LoadLevel(string levelName)
{
Application.LoadLevel (levelName);
}
void OnLevelWasLoaded()
{
myHUDController.PrepareLevel ();
}
Then in a different Scritp:
public void PrepareLevel()
{
Application.LoadLevelAdditive("UI");
JoinEverything ();
}
public void JoinEverything()
{
player = GameObject.FindGameObjectWithTag ("Player");
playerLife = player.GetComponent<DamageReceiver> ();
myPlayerActions = player.GetComponent<PlayerActions>();
lifeBar = GameObject.Find("LifeBar");
pauseMenu = GameObject.Find ("PauseMenuBtns");
ResumeGame ();
}
What happens is that the UI level is not loaded fast enouhg for the function JoinEverything finds the lifeBar and pauseMenu objects.
How can I solve this?
I tried for example, use the first scritp OnLevelWasLoaded and creat a conditional if level is UI then do this, but didn't work.
Any help with this?
P.S.: I'm using Unity 5.2.0f3 so the Applcation.LoadLevel is not yet useless... the project started with this version and we decided to stick to it.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
Help With Level Load 1 Answer