- Home /
DontDestroyOnLoad question
ok. i have a GUIText object with a score script attached and also a script shown below (dont destroy on load)
function Awake () {
DontDestroyOnLoad (this);
}
so my text and score will carry over to a new scene when its time up in my level. im just wondering how to move the position of the GUI text in my new scene without it effecting the position of it in the first scene. at the min the score is displayed at the top left hand side of the screen when playing, i would like it moved to around the centre of the screen on the new scene. i just dont have a clue where to start.
I appreciate any help
Answer by GesterX · May 08, 2011 at 04:42 PM
You could do this with a gameobject you name "LevelManager". The attach a "levelOne" script to it which finds the GUIText object and moves it in the Start() function. Simply have a different script for each level you want to move it in (or detect the level and move it).
So your game will do this:
- Load the new level
- Not destroy the GUIText
- Move the GUIText
This will all happen so fast you won't see it.
Alternatively you could use Application.loadedLevel to detect what level is loaded in a script attached to the GUIText itself and move it depending on what Application.loadedLevel returns.
thanks, this seems like a very simple method. does the awake function run before the start function then?
im stuck already >.< i think im on the right track though. i have
function Start () { GameObject.Find("$$anonymous$$eepScore").transform.position = Vector3(-615, 295, 0); }
is this right? because iv tried it like this and i cant see the text. im not sure if the x, y, z coords are totally out or this is the totally wrong script for doing it :/
Your answer
Follow this Question
Related Questions
Canvas will only appear on the game screen when its child of a new loaded scene canvas 1 Answer
NavMeshAgent (with DoNotDestroyOnLoad) Not Work After LoadScene; Transform Locked 0 Answers
DontDestroyOnLoad on disabled object doesn't work? 1 Answer
When I reload my Scene, nothing works. I think it's because of a dontDestroyOnLoad gameObject 0 Answers
DontDestroyOnLoad, where is my error? 2 Answers