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 bluesheep4 · May 12, 2020 at 09:14 PM · spawnspawnpoints

Multiple Spawn Points,Multiple Spawn Points in one scene

,So I have a game i'm making where there is a main room (scene) and it has little side rooms that come off of it (other scenes). The problem I have is about spawn points. I want to be able to enter another scene, and then when i exit that scene, I spawn near that door, instead of the first place you spawn in the game.

I've coded before but never really with C# and I've been able to do some v basic code, but this is a little beyond me, as i don't know the kinds of functions etc.

What I envision is a way to basically say "if (the scene before was scene 1) spawn point = this empty game object near the door, else if (scene before was scene 2 ) spawn point = different object , etc . i managed to do some code that enabled me to input a game object as the spawn point, but i could only do one, and it wasn't dependent on which scene i exited from.

Can anyone help me with like a basic way to code this? I know people don't usually get whole things of code in the answers, but if anyone could get me started that would be sick.

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
0
Best Answer

Answer by highpockets · May 12, 2020 at 09:13 PM

There are multiple ways that you can do this, but I think a simplistic approach could be to have a DoorManager class which persists between scenes, you can use DontDestroyOnLoad() to persist. And setup trigger colliders at each door which are have a tag name based on the location to spawn in the next scene and so you would have the position right when you enter the trigger.

 void OnTriggerEnter(Collider other){
     if(other.tag == “SouthDoorLobby”){
         positionToSpawn = southDoorLobbySpawnPoint;
     }
 }
 
 ///After loading
 transform.position = positionToSpawn;
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 bluesheep4 · May 12, 2020 at 10:00 PM 0
Share

@highpockets First off thank you for the quick reply and easy to read answer!

$$anonymous$$y next question is, so i have made a Door manager script, which is a Singleton correct? So i have made the script that supposedly holds information throughout the game, now do would i add this bit of code you've provided to the same script, or to another script that references my Door manager?

(i hope this makes sense and isn't a dumb question lmao)

avatar image highpockets bluesheep4 · May 13, 2020 at 07:02 AM 0
Share

Yes, that would be the idea. Just map out your doors with the trigger function:

 void OnTriggerEnter(Collider other){
     if(other.tag == “SouthDoorLobby”){
         spawnPoint = southDoorLobbyPosition;
     }
     else if(other.tag == “SouthDoorKitchen”){
         spawnPoint = southDoorKitchenPosition;
     }
 }
 

You can have all of those conditions in the trigger enter function on the door manager script.


Another way to do this would be to have a script on each of your doors. The Door class. If, for example, you have a lot of doors, this might be a better solution for you. Each door again would have a trigger collider attached to notify you when the player is there and then you could access that class from a script on the player. On the Door class:

 //this little trick is so you can set spawn point in the inspector and then never change it’s value, but you can access it with the public getter.
 [SerializeField]
 private Vector3 _spawnPoint;
 [HideInInspector]
 public Vector3 spawnPoint{
     get{ return _spawnPoint; }
 }
 
 

Then on a script attached to the player:

 void OnTriggerEnter(Collider other){
     if(other.tag == “door”){
         doorScript = other.gameObject.GetComponent<Door>();
         spawnPoint = doorScript.spawnPoint;
     }
 }

That solution is more elegant I$$anonymous$$O

avatar image bluesheep4 · Nov 10, 2020 at 04:08 PM 0
Share

@highpockets hello i am back lmao. i put this game on hold and im common back to it now, and i am revisiting this page in order to execute this script, and I'm gonna ask if you can help me a little more with this code if thats alright lmao! I really appreciated your answer at the time, but since its been a $$anonymous$$ute and ive not been in the coding headspace, and i never finished the script at the time, i need to ask you a question.

if I have the Door$$anonymous$$anager class and it persists, i put this code to map out my doors, but 1) how to i plug in an actual "point" ie location to spawn where you've designated the example "south doorlobbyspawnpoint" and 2) how do i signify "//after loading", should i use a function that has to do with the scene loading or what?

Thank you I hope you see this and can help me more now that my brain has lost the coding lmao

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

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Quaternion.identity problem at random spawn 1 Answer

How do I spawn more the one spawnpoints ramdomly in my scene / Spawning problems 0 Answers

[Help] How Do I Randomly Spawn Game Objects On Specific Coordinates? 3 Answers

How do I control where enemies spawn? 1 Answer

Is it possible to instantiate a prefab in 2d game from particular locations without using empty game object? 2 Answers


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