Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

'DontDestroyOnLoad' is destroying other gameobjects

$
0
0
HI :) I have a game manager (empty gameobject) which i want to go from level to level as my player progresses. On the game manager, is a score keeping script (in java script), within the 'Awake' function is the line 'DontDestroyOnLoad(transform.gameObject);'. **Here's the problem:** When i load a new level using: Application.LoadLevel ("Star Counter"); The gameobjects in the new scene are displayed as 'deleted gameobject' and can't be selected - The camera is still showing the scene (but is listed as a 'deleted gameobject') - The background is still shown, but the texture isn't scrolling (as i programmed it to do...and is listed as a 'deleted gameobject') *If i remove the DontDestroyOnLoad line from the game manager, the gameobjects in the new level are fine.* Why is this happenening, how can it be fixed? Thank you as always for your time, Tom :) **(EDIT)** The game manager holds the scores (collected stars) and the GUI for the game and loads the next level when needed. Here's the script: var zoe : GameObject; var kim : GameObject; // Star counting: /////////////////////////////////////// var zoeStarsYellow : int; var kimStarsYellow : int; var zoeStarsBlue : int; var kimStarsBlue : int; var zoeStarsGreen : int; var kimStarsGreen : int; var zoeStarsRed : int; var kimStarsRed : int; var zoeStarsCon1 : int; var kimStarsCon1 : int; var totalYellowStars : int; var totalBlueStars : int; var totalGreenStars : int; var totalRedStars : int; ///////////////////////////////////////////////////////// var seesaw : GameObject; // GUI Junk: //////////////////////////////////////////// var bWidth1 : float = 10; //size of game GUI boxes var bHeight1 : float = 15; var sWidth1 : float = 10; //position of game GUI Textures var sHeight1 : float = 10; var sWidth2 : float = 10; var sHeight2 : float = 10; var sWidth3 : float = 10; var sHeight3 : float = 10; var sWidth4 : float = 10; var sHeight4 : float = 10; var sWidth5 : float = 10; var sHeight5 : float = 10; var enableGameGUI : boolean = true; var enableCounterGUI : boolean = false; var bWidth2 : float = 10; //size of counter GUI boxes var bHeight2 : float = 15; var yellowWidth1 : float = 10; //position of counter GUI Textures var yellowHeight1 : float = 10; var blueWidth2 : float = 10; var blueHeight2 : float = 10; var greenWidth3 : float = 10; var greenHeight3 : float = 10; var redWidth4 : float = 10; var redHeight4 : float = 10; var yellowStarsNeeded : int; var blueStarsNeeded : int; var greenStarsNeeded : int; var redStarsNeeded : int; var jumpsLeft : int; var maxJumps : int; var gooeyTextYellow : GUIStyle; var gooeyTextBlue : GUIStyle; var gooeyTextGreen : GUIStyle; var gooeyTextRed : GUIStyle; var gooeyJumpsLeft : GUIStyle; var gooeyTextYellow2 : GUIStyle; var gooeyTextBlue2 : GUIStyle; var gooeyTextGreen2 : GUIStyle; var gooeyTextRed2 : GUIStyle; var gooeyTick : GUIStyle; var gooeyCross : GUIStyle; var yellowSuccess : boolean; var blueSuccess : boolean; var greenSuccess : boolean; var redSuccess : boolean; ///////////////////////////////////////////////////////// function Awake () { DontDestroyOnLoad(transform.gameObject); seesaw = gameObject.Find("JumpManager"); zoe = gameObject.Find("P1"); kim = gameObject.Find("P2"); jumpsLeft = -2; maxJumps = 2; if (Application.loadedLevelName == "sceneTest") { enableGameGUI = true; enableCounterGUI = false; totalYellowStars = 0; totalBlueStars = 0; totalGreenStars = 0; totalRedStars = 0; yellowStarsNeeded = 100; blueStarsNeeded = 100; greenStarsNeeded = 100; redStarsNeeded = 100; } if (Application.loadedLevelName == "Star Counter") { enableGameGUI = false; enableCounterGUI = true; } } function Update () { totalYellowStars = (zoeStarsYellow + kimStarsYellow); totalBlueStars = (zoeStarsBlue + kimStarsBlue); totalGreenStars = (zoeStarsGreen + kimStarsGreen); totalRedStars = (zoeStarsRed + kimStarsRed); if (jumpsLeft >= maxJumps) { loadStarCounter (); //Application.LoadLevel ("Star Counter"); print ("End Of Level"); } if (enableCounterGUI == true) { if (totalYellowStars >= yellowStarsNeeded) { yellowSuccess = true; } else { yellowSucess = false; } } } function OnGUI () { if (enableGameGUI == true) { GUI.Label (Rect (Screen.width/sWidth1, Screen.height/sHeight1, Screen.height/bHeight1, Screen.height/bHeight1), totalYellowStars.ToString() + "/" + yellowStarsNeeded.ToString(), gooeyTextYellow); GUI.Label (Rect (Screen.width/sWidth2, Screen.height/sHeight2, Screen.height/bHeight1, Screen.height/bHeight1), totalBlueStars.ToString() + "/" + blueStarsNeeded, gooeyTextBlue); GUI.Label (Rect (Screen.width/sWidth3, Screen.height/sHeight3, Screen.height/bHeight1, Screen.height/bHeight1), totalGreenStars.ToString() + "/" + greenStarsNeeded, gooeyTextGreen); GUI.Label (Rect (Screen.width/sWidth4, Screen.height/sHeight4, Screen.height/bHeight1, Screen.height/bHeight1), totalRedStars.ToString() + "/" + redStarsNeeded, gooeyTextRed); GUI.Label (Rect (Screen.width/sWidth5, Screen.height/sHeight5, Screen.height/bHeight1, Screen.height/bHeight1), jumpsLeft.ToString() + "/" + maxJumps.ToString(), gooeyJumpsLeft); } if (enableCounterGUI == true) { GUI.Label (Rect (Screen.width/yellowWidth1, Screen.height/yellowHeight1, Screen.height/bHeight1, Screen.height/bHeight1), "Yellow Stars: " + totalYellowStars.ToString() + "/" + yellowStarsNeeded.ToString(), gooeyTextYellow2); GUI.Label (Rect (Screen.width/blueWidth2, Screen.height/blueHeight2, Screen.height/bHeight1, Screen.height/bHeight1), "Blue Stars: " + totalBlueStars.ToString() + "/" + blueStarsNeeded, gooeyTextBlue2); GUI.Label (Rect (Screen.width/greenWidth3, Screen.height/greenHeight3, Screen.height/bHeight1, Screen.height/bHeight1), "Green Stars: " + totalGreenStars.ToString() + "/" + greenStarsNeeded, gooeyTextGreen2); GUI.Label (Rect (Screen.width/redWidth4, Screen.height/redHeight4, Screen.height/bHeight1, Screen.height/bHeight1), "Red Stars: " + totalRedStars.ToString() + "/" + redStarsNeeded, gooeyTextRed2); if (yellowSuccess == true) { GUI.Label (Rect (Screen.width/yellowWidth1, Screen.height/yellowHeight1, Screen.height/bHeight1, Screen.height/bHeight1), " " ,gooeyTick); } else { GUI.Label (Rect (Screen.width/yellowWidth1, Screen.height/yellowHeight1, Screen.height/bHeight1, Screen.height/bHeight1), " ", gooeyCross); } } } function loadStarCounter () { enableGameGUI = false; enableCounterGUI = true; Application.LoadLevel ("Star Counter"); }

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>