having problems reloading a scene after it has been unloaded
I am currently making an RPG, and there are a lot of scenes that need to be loaded/unloaded ( towns, dungeons, etc) I can leave my would map, and enter a town, and leave the town and enter the world map. When I go to enter the town again, Where it should load up again, The screen just fades, but the player doesn't enter the town, he stays in the same transform that he was in. It has to have something to do with how I am loading/unloading my scenes, but I for some reason can't see it. Any help would be appreciated. My load and unload scripts are as follows: Loading: using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
public class intoJail : MonoBehaviour { public int sceneToLoad;
[SerializeField]
Transform jailbuilding;
private GameObject Player;
private bool Loaded = false;
void Start()
{
Player = GameObject.FindGameObjectWithTag("Player");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
ScreenFader.CreateFade("ScreenFadeDown", FadeDownCompleted);
}
}
void FadeDownCompleted()
{
if (!Loaded)
{
SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive);
//moves the player character to a different location on the grid
Player.transform.position = jailbuilding.transform.position;
Player.transform.rotation = jailbuilding.transform.rotation;
Loaded = true;
}
else
{
return;
}
}
}
Unloading:
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
public class UnloadWorldMap : MonoBehaviour {
public int unloadScene;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
StartCoroutine(UnLoadScene());
}
}
IEnumerator UnLoadScene()
{
yield return new WaitForSeconds(0f);
SceneManager.UnloadScene(unloadScene);
}
IEnumerator ClearLevel()
{
yield return new WaitForSeconds(1.0f);
Resources.UnloadUnusedAssets();
}
}
Thank you in advance!
Your answer
Follow this Question
Related Questions
How can i get a Rotation X.Y.Z for a save file 1 Answer
my counter wont change from 0 help 1 Answer
Need help with bone animation and trigger code. 0 Answers
OnTriggerEvent doesn't work 1 Answer