Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • 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.

which is an object with a set position thisPosition to which this 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 thisPosition;
 
     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 = thisPosition;
         }
     }
 
     void Update() {      
         thisPosition = new Vector2(-64.01f, -16.01f);
         //check for last bench position
             if (controller.respawned && thisPosition == gm.lastBenchPos) {
                 LoadScene(Load_Home);
                 Physics2D.IgnoreLayerCollision(7, 8, false);
                 Physics2D.IgnoreLayerCollision(7, 9, false);
                 player.transform.position = thisPosition;
                 //check for child 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 nothing 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, which has different coordinates.

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

im trying to make this work since 3 full days and im slowly descending into madness because i need to have this 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.

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

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

How should I approach in switching my scenes? 0 Answers

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

Keeping track of the previous scene 1 Answer

How to change scenes based on an if else statement C# 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