Я знаю, что об этом уже спрашивали здесь , но это не работает.Он успешно перемещает GameObject в другую сцену, но не закрывает предыдущую сцену.Вот снимок экрана .
Вот расширенный снимок экрана проекта Расширенный снимок экрана
А вот сценарий, но в сценарииВы также найдете код меню слайд-шоу, в котором мои модели будут отображаться как меню
В функции enableScene () В строке 1 я пытался закрыть предыдущую сцену, но она не работает
public class PizzaScript : MonoBehaviour {
public Text header;
public List<GameObject> createObjects = new List<GameObject>();
private static int slideIndex = 1;
private GameObject instance;
private Vector3 temp = new Vector3(0.34f, 0.074f, 0);
private AsyncOperation sceneAsync;
public GameObject Pizza;
public GameObject Cube;
public GameObject Sphere;
public GameObject CocaCola;
// Use this for initialization
void Start()
{
object[] subListObjects = { Pizza, Cube, Sphere, CocaCola };
foreach(GameObject list in subListObjects )
{
GameObject lo = (GameObject)list;
createObjects.Add(lo);
}
showPrefabs(slideIndex);
StartCoroutine(loadScene(2));
}
IEnumerator loadScene(int index)
{
AsyncOperation scene = SceneManager.LoadSceneAsync(index, LoadSceneMode.Additive);
scene.allowSceneActivation = false;
sceneAsync = scene;
//Wait until we are done loading the scene
while (scene.progress < 0.9f)
{
Debug.Log("Loading scene " + " [][] Progress: " + scene.progress);
yield return null;
}
Debug.Log("Progress Completed.............................");
}
public void OnFinishedLoadingAllScene()
{
Debug.Log("Done Loading Scene");
enableScene(2);
Debug.Log("Scene Activated!");
}
private void enableScene(int index)
{
SceneManager.UnloadSceneAsync(1);
//Activate the Scene
sceneAsync.allowSceneActivation = true;
Scene sceneToLoad = SceneManager.GetSceneByBuildIndex(index);
if (sceneToLoad.IsValid())
{
Debug.Log("Scene is Valid");
SceneManager.MoveGameObjectToScene(instance, sceneToLoad);
SceneManager.SetActiveScene(sceneToLoad);
}
}
// Update is called once per fram
public void OnClickRightArrow()
{
plusPrefabs(1);
}
public void OnClickLeftArrow()
{
plusPrefabs(-1);
}
public void plusPrefabs(int n)
{
if(n == 1 || n == -1)
{
Destroy(instance,0.01f);
}
showPrefabs(slideIndex += n);
}
public void showPrefabs(int n)
{
var x = createObjects.Count;
if (n > createObjects.Count)
{
slideIndex = 1;
}
if (n < 1)
{
slideIndex = createObjects.Count;
}
if (slideIndex == 1)
{
header.text = slideIndex.ToString();
instance = Instantiate(createObjects[0], temp, Quaternion.Euler(-90,0,0));
instance.transform.localScale = new Vector3(20, 20, 20);
}
else if(slideIndex == 2)
{
header.text = slideIndex.ToString();
instance = Instantiate(createObjects[1], temp, transform.rotation);
instance.transform.localScale = new Vector3(10, 10, 10);
}
else if (slideIndex == 3)
{
header.text = slideIndex.ToString();
instance = Instantiate(createObjects[2], temp, transform.rotation);
instance.transform.localScale = new Vector3(10, 10, 10);
}
else if (slideIndex == 4)
{
header.text = slideIndex.ToString();
instance = Instantiate(createObjects[3], temp, Quaternion.Euler(-90,0,0));
instance.transform.localScale = new Vector3(120, 120, 120);
}
}
}
Вот снимок экрана Снимок экрана предыдущей сцены