Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ianawright · Nov 25, 2014 at 08:20 AM · instantiatespawnlevelspawnpointsonlevelwasloaded

one scene multiple spawn points

Hey! Please refrain from roasting me as I am a new developer and inexperienced coder but in my game I have a main room which has doors which load different scenes. I'd like to return to the scene with a spawn point for the player which is as if he had just opened the door from the room. I know I can do this by making multiple copies of the scene but that is tedious and not sustainable.

I'd like to be able to call to assign the gameobject and correct transforms for the player through the level loader/door script in the last scene heres what I have

 using UnityEngine;
 using System.Collections;
 
 public class PlayDoor : MonoBehaviour {
     public int  button1function;
     public float  width;
     public Transform player;  //transform for the player
     public float height;
     public GameObject playercontroller; //gameobject of player
         public string  ScreenText;
         private bool  enter;
         void  OnTriggerEnter ( Collider other  ){
 
             enter = true;
         }
         void OnGUI  (){
     
                 if (enter) {
                         GUI.Label (new Rect (Screen.width / 2 - width, Screen.height - height, 150, 30), ScreenText);
                         if (Input.GetKeyDown ("f")) {
                                 audio.Play ();
                 AutoFade.LoadLevel (button1function, (1 / 2), 1, Color.black);
                                 }
                         }
                 }
     void OnLevelWasLoaded(int level) //not sure if this is even possible or the correct usage of onlevelwasloaded, but to my understanding it calls something to be done right as the next scene was loaded? {
         if (level == 0)
         Instantiate (playercontroller,transform.position, transform.rotation );
     }
         void OnTriggerExit ( Collider other  ){
             enter = false;
 
     }
 }



If anyone knows how to fix this code/have multiple spawns in a simpler way and can point me in the right direction please let me know. My apologies if this answer is self evident and I am just lost.

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

Answer by Andres-Fernandez · Nov 25, 2014 at 08:31 AM

You almost have said it yourself: "I'd like to be able to call to assign the gameobject and correct transforms for the player through the level loader/door"

What you need is one persistent script that holds the position of the player when the scene loads. You need to create an object, use DontDestroyOnLoad to make it persistent (also use a singleton pattern to avoid duplicating the object, just google "unity singleton") and make it have a reference to the spawn point. When using a door, store the reference to that spawn point in your persistent object. Then, whenever you reload the scene, the persistent script can instantiate the player in the correct position.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Spawn player to a different scene 0 Answers

I'm having problems with my code 1 Answer

How do I spawn an object under another moving object at random in C#? 1 Answer

How do I control where enemies spawn? 1 Answer

Prevent object from spawning at a spawn point twice in a row? 3 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