Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TaintedSeraphim · Apr 28, 2010 at 07:02 PM · spawnchangemusicpointsportal

How do I create an effective spawn point script for multiple scenes and change music each scene?

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:

var SpawnPoint : GameObject;

function OnLevelWasLoaded() { SpawnPoint = GameObject.FindWithTag("SpawnPoint"); transform.position(SpawnPoint.transform); }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by StephanK · Apr 28, 2010 at 07:17 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TaintedSeraphim · Apr 28, 2010 at 07:49 PM 0
Share

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.

avatar image StephanK · Apr 28, 2010 at 09:50 PM 1
Share

ins$$anonymous$$d 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.

avatar image Dealzu-The-Wikid · Jul 15, 2014 at 08:51 PM 0
Share

For some reason this still does not load the player into the proper position... It still wants to load at the original position the object was created in....Even if youve deleted this, even with this code in the OnLevelWasLoaded function, the player still seems to be overridden by some kindof internal Unity player preference save.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to change a model into an other model without clone-ing 1 Answer

problem changing spawnTime variable 1 Answer

How to start/stop/loop different music tracks 0 Answers

Spawning In Photon C# 1 Answer

portal problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges