x


DestroyOnLoad???

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

DontDestroyOnLoad(transform.gameObject);

but it`s still destroyed. How can i fix it ?

more ▼

asked Jul 22 '12 at 06:43 AM

m4s4m0r1 gravatar image

m4s4m0r1
122 2 11 20

r u sure that this command is executed? which command do you use for load level?

Jul 22 '12 at 06:45 AM ScroodgeM

the second scene is Main Menu so i use the command like this

function OnMouseDown() { Application.LoadLevel("Scene3") }

Jul 22 '12 at 06:54 AM m4s4m0r1

try to call DontDestroyOnLoad immediately before call LoadLevel

Jul 22 '12 at 07:07 AM ScroodgeM

ok i`ll try it... sorry sir can you make a script for loading script please? i cant found anywhare.

Jul 22 '12 at 07:37 AM m4s4m0r1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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.

more ▼

answered Jul 22 '12 at 07:46 AM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2091
x764

asked: Jul 22 '12 at 06:43 AM

Seen: 361 times

Last Updated: Jul 22 '12 at 07:46 AM