• 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 /
  • Help Room /
avatar image
0
Question by edganmolla · Dec 26, 2021 at 06:14 PM · scene-switchingvector2teleportingscene changecheckpoint

Can't teleport to checkpoint/bench in other scene upon death. please help me.

hello there! ive got a problem with a hollow knight-like bench system. upon dying, i want the player to respawn in another scene at a certain point.

w$$anonymous$$ch is an object with a set position t$$anonymous$$sPosition to w$$anonymous$$ch t$$anonymous$$s script is attached:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 public class Bench_Home : MonoBehaviour {
     
     private CharacterController2D controller;
     public GameManagerScript gm;
     static string Load_Home = "Home";
     private GameObject player;
     public Vector2 t$$anonymous$$sPosition;
 
     void Start() {
         //WICHTIG!!! reference so machen, um auch bei scene change die reference zum script zu behalten   
         if (gm == null) {
             gm = GameObject.FindGameObjectWithTag("Player").gameObject.GetComponent<GameManagerScript>();
         }
         if (controller == null) { 
             controller = GameObject.FindGameObjectWithTag("Player").GetComponent<CharacterController2D>(); 
         }
         if (player == null) {
             player = GameObject.FindGameObjectWithTag("Player");
         }
     }
 
     void OnTriggerEnter2D(Collider2D other) {
         if (other.CompareTag("Player")) {
             gm.lastBenchPos = t$$anonymous$$sPosition;
         }
     }
 
     void Update() {      
         t$$anonymous$$sPosition = new Vector2(-64.01f, -16.01f);
         //check for last bench position
             if (controller.respawned && t$$anonymous$$sPosition == gm.lastBenchPos) {
                 LoadScene(Load_Home);
                 Physics2D.IgnoreLayerCollision(7, 8, false);
                 Physics2D.IgnoreLayerCollision(7, 9, false);
                 player.transform.position = t$$anonymous$$sPosition;
                 //check for c$$anonymous$$ld object and enable
                 controller.rb.gravityScale = 3;
                                 
             }
             controller.respawned = false;
     }
 
 
     public static void LoadScene(string SceneNameToLoad) {
         PendingPreviousScene = SceneManager.GetActiveScene().name;
         SceneManager.sceneLoaded += ActivatorAndUnloader;
         SceneManager.LoadScene(SceneNameToLoad, LoadSceneMode.Additive);
         Debug.Log("Home was loaded");
     }
 
     static string PendingPreviousScene;
     static void ActivatorAndUnloader(Scene scene, LoadSceneMode mode) {
         SceneManager.sceneLoaded -= ActivatorAndUnloader;
         SceneManager.SetActiveScene(scene);
         SceneManager.UnloadSceneAsync(PendingPreviousScene);
     }
 
 
 }
 

when i instantiate my player, i am spawned at the location of gm.lastBenchPos and upon interaction with another "bench", i want gm.lastBenchPos to update.

in the inspector not$$anonymous$$ng happens, but if i put a Debug.Log(lastBenchPos) into Update() of GameManagerScript, the values are changing.

GameManagerScript is attached to the Player(Clone) created from prefab.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GameManagerScript : MonoBehaviour
 {
     public Vector2 lastCheckPointPos;
     public Vector2 lastBenchPos;
 }
 

i need the values to be able to fullfil the if-statement of the other bench, w$$anonymous$$ch has different coordinates.

and make it able for the player to teleport there upon death.

im trying to make t$$anonymous$$s work since 3 full days and im slowly descending into madness because i need to have t$$anonymous$$s figured out. please help me.

thanks in advance!

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 edganmolla · Dec 26, 2021 at 06:15 PM

oh i forgot. when dying, the player returns to the first "bench" but never to the 2nd, even when having interacted with the 2nd bench.

and upon interacting with the 2nd bench and dying after it, the if-condition doesnt seem to be fulfilled.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

174 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

Related Questions

is there a way to teleport the player to a certain coordinate right after loading a scene? 0 Answers

How I can Open a Previous Scene with button back !? 3 Answers

How to navigate from a non-VR scene to a VR enabled scene within Android 2 Answers

Dotween show error when changing scene 0 Answers

2D sliding scene transition like old Zelda games. 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