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 MysteryBR54 · Jun 30, 2019 at 05:36 PM · 2d2d game2d-platformerspawnpointsspawnpoint

2D Platformer multiple spawnpoints

I'm making a 2D platformer game right now, and i want to move between areas but i want some areas to have multiple spawnpoints. The way it works, A player goes through a portal and it loads a new scene, and in that new scene there are another 2 portals, one that loads the scene the player came from(I will call it portal 1) and another portal that loads the next scene(and this portal i will call portal 2). Now i want the player to spawn in the portal 1 because that's the one that will lead him back to the scene that he just came from. Now i could just set the spawnpoint in portal 1 but the problem is, that portal 2 loads the next scene where in that next scene, you can come back to portal 2, But how can i make the player spawn in portal 2 if there is a spawnpoint in portal 1? Now because i'm very bad at explaining i will try to draw it,I will appreciate every help, Thank you! I'm getting an error when trying to upload the image so i uploaded it to google drive: https://drive.google.com/file/d/1ydIXKw8LfFK_DvdgXRyFChk_zHbC7A44/view?usp=sharing (The circle in the middle is another scene btw)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Optrix · Jul 01, 2019 at 06:04 AM

You can use a static variable, or alternatively you can have a GameObject that uses https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

DontDestroyOnLoad allows a GameObject to persist between scenes.

You can have a GameObject containing the full state of your game - number of lives, player name, Facebook PI details, and the name of the last portal they passed through - and any required network connections etc. that survives between scenes. When you load the new scene, you check which portal they used and choose which spawn point to pick.

Comment
Add comment · Show 2 · 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 MysteryBR54 · Jul 01, 2019 at 07:21 AM 0
Share

Yeah i know what is DontDestroyOnLoad but i', not sure how can i know which portal i went trough but i think i have an idea. Every time that i use a Portal, it will send the name of the portal to the gameobject but i'm thinking how. Here is my script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class Portal : $$anonymous$$onoBehaviour
 {
     public bool CanTeleport;
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         if(CanTeleport == true)
         {
             if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.UpArrow))
             {
                 Scene$$anonymous$$anager.LoadScene("NextWorld");
             }
         }
     }
 
     private void OnTriggerStay2D(Collider2D collision)
     {
         if(collision.gameObject.tag == "Player")
         {
             CanTeleport = true;
         }
         else
         {
             CanTeleport = false;
         }
     }
 }

I have some ideas, i will try them right now, Thank you, even though i knew about DontDestroyOnLoad i didn't think about an empty gameobject that will store the state of my game, Thank you! Edit: i'm always having trouble accessing another script's variables, can you tell me what is the best way? for now i just do this: GameObject.Find("Game Status").GetComponent<GameState>().lastportal = PortalName;

avatar image MysteryBR54 MysteryBR54 · Jul 01, 2019 at 08:38 AM 0
Share

Hey, i did it! Thank you so much. Problem Solved :P

avatar image
0

Answer by xxmariofer · Jun 30, 2019 at 06:54 PM

add a spawnscript to each portal, the only thing you need in there is a collisionenter event, and compare the collider of the object that has just collided. you can have a public transform variable in the spawnscript for handleling where do you want to spawn respawn the object. there are hundreds of fancier ways of doing this but this one is the easiest one

Comment
Add comment · Show 8 · 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 MysteryBR54 · Jun 30, 2019 at 07:12 PM 0
Share

Yeah, but how can i know from which portal the player just came from? Because if he came from scene 1 he needs to spawn in portal 1, and if he came from scene 2, he needs to teleport in portal 2. There are two spawnpoints that the player can spawn in.

avatar image AaronBacon MysteryBR54 · Jun 30, 2019 at 07:37 PM 0
Share

You could use a Static variable on an object that persists across scenes, or possibly use PlayerPrefs to save a value temporarily so on the other side you can check where the player came from and run the according code

avatar image xxmariofer MysteryBR54 · Jun 30, 2019 at 08:02 PM 0
Share

From portal 2 you can only go to spawn point a, or i am wrong?

avatar image MysteryBR54 xxmariofer · Jun 30, 2019 at 09:40 PM 0
Share

From portal 2 you can go to scene 2, and from scene 2 you can go to portal 2 that is located in a different scene. if it's hard to understand, if you know by any chance the game $$anonymous$$apleStory, i want something like that.

Show more comments

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

234 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 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

,Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis). 1 Answer

Level design clone of King of Thieves 0 Answers

Softbody physics with 2D sprites 1 Answer

How to blur 2D background sprites? 0 Answers

Timer jitters? SOLVED 0 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