- Home /
Character duplicates herself when re-entering the home level
Hello- so I just applied this script to a general object in the home level and set it as a trigger
function OnTriggerEnter(other : Collider) { Application.LoadLevel("scene 2"); }
and made another level with a another general object the same way to go back to the home level.
I also put this on the player, a npc that follows her throughout the game, and the main camera. I deleted the main camera in the second level to keep the one from the home level.
function Awake () { DontDestroyOnLoad (this); }
The player, npc, and camera transport perfectly to the second level, but when I hit the object in the second level to go back home, the player, npc, and camera, duplicate each time! How do I make sure the game retains the original player, npc, and camera no matter which level I enter or re-enter? Also, how do I allow any item they might holding (and only that item) to transport with the player or npc if they are holding it?
Thanks for any help
Answer by Rennat · Dec 01, 2010 at 09:29 AM
The way I handle this kind of situation is to have an extra scene with just the player (or object that needs to persist through scene loads)
What you have
- 2 scenes: Scene AandScene B.
- Scene Ahas a- Playerand the environment.
- Scene Bjust has the environment.
- When Scene Aloads it creates thePlayerand tells itDontDestroyOnLoad.
- Scene Bis loaded and the- Playercomes along for the ride.
My approach
- 3 scenes: Scene Loader,Scene A, andScene B
- Scene Loaderhas a- Playerand a script to load the next scene
- Scene Aand- Scene Bjust have the environments
- When Scene Loaderis loaded it creates thePlayerand tells itDontDestroyOnLoadthen immediately loadsScene A
- Scene Ais loaded and the- Playercomes along for the ride.
This worked liked like a dream! $$anonymous$$akes sense too. Thank you so much for your help!
Answer by Zu01 · Dec 01, 2010 at 10:33 AM
That, or you could try useing one gargantic scene =). That is exactly what I do sometimes.
Your answer
 
 
             Follow this Question
Related Questions
Random level select 1 Answer
Load Scene 1 Answer
Input.GetMouseButton on multiple objects 1 Answer
Load level after Image Sequence 0 Answers
checkpoint level please 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                