|
Hi, I'm trying to create spawn points and an automatic music changer, but I can't seem to figure out how to make either one work. The reason I need spawn points is I've got these portals that teleport the player to each new level, and the portals play a sound effect upon collision with the player. But in order to play the sound effect all the way through, the audio source has to be attached to an object that doesn't get destroyed when the new scene loads. Now I've managed to get that part working fine by setting both the camera and player character to DoNotDestroy (the teleportaion sound effect is attached to an empty game object called "Portal Sound", which is itself attached to the main camera), but now the player character retains his old coordinates from wherever he was standing in the previous scene when the new scene loads, and I need to be able to specify an exact location for him to spawn at in the new scene. Also I need the music to change automatically when each new scene loads, as each level has its own theme music. EDIT: Here's the code I've got so far, but it doesn't seem to work:
(comments are locked)
|
|
Just attach an empty GameObject to each scene called SpawnPoint and on scene load set the players transform.position to the position of SpawnPoint. To change music you could just create a second audio source and crossfade with the old one. You could do all this in the OnLevelWasLoaded() method. And how exactly do I set the player's transform.position to the position of SpawnPoint? I've edited the original question to include my code.
Apr 28 '10 at 07:49 PM
TaintedSeraphim
instead of transform.position(SpawnPoint.transform) do this: transform.position = spawnPoint.transform.position; On another note variables should always start with a small letter to make it easier to differentiate them from functions and types.
Apr 28 '10 at 09:50 PM
StephanK
(comments are locked)
|
