- Home /
Don't destroy script on load
Hi all, I'm confronted to a problem.
I've a script in my player to score when I pick up a coin (Like in Mario games).
But I don't want to lose current score when loading a level.
Ok so it's easy right ?
But I've 2D Scene, character changes, and other stuff like that in the game.
Question :
How to always have the score in my screen and don't destroy him each load scene ?
I need to keep the score script on each player character ? I need to put the score script somewhere else ?
Answer by Graham-Dunnett · Oct 23, 2014 at 08:07 PM
http://docs.unity3d.com/ScriptReference/ScriptableObject.html and
http://docs.unity3d.com/ScriptReference/HideFlags.DontSave.html
(but you've read the docs, right? ;-))
I'm french and I don't know the name of what I'm looking for ^^ Thank you, I'll read this ! By the way, I've internet only one day per week so I can't look for others threads... And I didn't know the name of this "thing"... :/ In my unity workstation, I've only unity, Fl STudio and 3D Softwares. EDIT : Ok so, if I put this :
function Start() { var notDestructable : GameObject; // Assign the score object in inspector notDestructable.hideFlags = HideFlags.DontSave; }
$$anonymous$$y Score object will never destroy ?
Answer by Fragmental · Mar 12, 2017 at 08:34 AM
I know this is like 2 and half years old, but:
DontDestroyOnLoad(gameObject);
?