- Home /
Respawn pick up objects when scene is loaded?
So after a player picks up an object, the object is destroyed. However I was wondering if there was a way to respawn the object once the player changes scenes? For example, when the player gets the game over scene and hits replay, how can I make it so the pick ups aren't destroyed and are available for the player to pick up again? I was considering using something like
Void Awake (){
if (!gameObject) {
Instantiate(someobject);
}
}
Answer by Ouss · Dec 06, 2014 at 09:04 PM
If you load the scene again there should be no problem if you didn't declare gameobject as static. add gameObject = false; before if statement and then add gameObject = true; below Instantiate instruction if you want to instantiate your object once in the scene. if you don't load your scene again then you should reset your variable manually in a seperate method for exemple, set gameobject to false, you call Awake in it. void Reset(){
Awake();
}
Your answer
Follow this Question
Related Questions
changing the 3D character or character's body after picking up an object 0 Answers
Preserve state of objects when stopping game 0 Answers
Check if object is destroyed on level load, if so instantiate prefab? 1 Answer
Calling 2 specific random float numbers in random.range using array not working! 2 Answers
how to instantiate object with content prefab and not him self 2 Answers