|
hey, i have a problem with my scene now. i have a 3 scene in my project. if i open third scene from second scene it`s no problem. But, my problem is if i open the second scene from first scene then i open the third scene from the second scene, My gameObject is Destroy ! I have attach the script that have function but it`s still destroyed. How can i fix it ?
(comments are locked)
|
using UnityEngine;
using System.Collections;
public class SceneLoader : MonoBehaviour
{
void Start()
{
DontDestroyOnLoad(gameObject);
}
void OnGUI()
{
if (GUI.Button(new Rect(5, 5, 100, 30), "scene 1")) { Application.LoadLevel("scene1"); }
if (GUI.Button(new Rect(5, 35, 100, 30), "scene 2")) { Application.LoadLevel("scene2"); }
if (GUI.Button(new Rect(5, 65, 100, 30), "scene 3")) { Application.LoadLevel("scene3"); }
}
}
this script attached to some GameObject keeps this GameObject from destroying and always shows a menu for select one of 3 scenes to load. note that scenes with these names must exists and be included in build options. pressing a gui button loads selected scene as well.
(comments are locked)
|

r u sure that this command is executed? which command do you use for load level?
the second scene is Main Menu so i use the command like this
function OnMouseDown() { Application.LoadLevel("Scene3") }
try to call DontDestroyOnLoad immediately before call LoadLevel
ok i`ll try it... sorry sir can you make a script for loading script please? i cant found anywhare.