- Home /
how do you save an instantiated object in the heirarchy. meaning when i unpause the game its still there.
hello, ive been stumped on this problem. I need to save this object (some kind of Highscore Line) where when the player dies. it leaves an object(Highscore Line) and so when i restart the game or unpause and play it again the instanitated object(Highscore Line) would be still there? Instantiate(HighScoreLine,new Vector3(Player.position.x,0,0),Quaternion.identity);
Answer by KayelGee · Jun 18, 2015 at 01:15 PM
There are multiple options. The easiest would be to save each death to a file on your pc and when you start your game you read that file and instantiate objects with that information.
A little more complex solution would be to setup a database and save deaths into it and loading from it at the start of the game again. This solution would make sense if you want the deaths of all your players to be visible to all players.
However you do it the principle will be the same. You save your data somewhere in someway and load it at game start.
Im sorry but my question wasn't clear. my game is a 2d infinite runner running in the right side. I need to save that object even without pausing the editor. my purpose is to create some kind of finish line (the object)that would be instantiated on the position when you first die with your first highscore. so when I click the restart button. the next time i will get closer to the first high score i got would have a finish line on it and the player would break that finish line telling the player that he beat his previous highscore. and when he dies again that would instantiate another finish line on the spot that he died Instantiate(HighScoreLine,new Vector3(Player.position.x,0,0),Quaternion.identity);
so i need some kind of method. that would do that for me without unpausing the editor. im really sorry sir
It's effectively the same answer. Just save the high score somewhere and load it when the game starts. PlayerPrefs is a good place for that. You should know where a particular score shows up in your game progress, so you can insantiate the finish line at that position based on the score.
Answer by rhbrr5hrfgdfgw · Jun 18, 2015 at 03:42 PM
I have an idea, you can save an integer(PlayerPrefs) and when you die and you are above high score
if(dead && score > highScore){
//Save the integer with playerprefs
}
and then every time you start the game you can instantiate using the integer you saved. You might have some problems since the integer value isn't like x value but thats a nice start to the code.
Your answer
