Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How can Player get back to the coordinates of C scene?

Discussion in '2D' started by FreeJus, Jul 15, 2022.

  1. FreeJus

    FreeJus

    Joined:
    Feb 9, 2022
    Posts:
    2
    Hello, I am studying UNITY while looking at the textbook.
    When Player move from A scenes to B scenes or from A Scenes to C scenes work well.
    However When the player moves from C scene to A scene,
    It returns to B scene coordinate.
    How can It get back to the coordinates of C scene?
    I'm looking for help. Thank you.

    ++) Please recommend lectures and books that can help solve the problem. Thank you.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class StartPoint : MonoBehaviour
    5. {
    6.     public string startPoint;
    7.     private PlayerManager thePlayer;
    8.     private CameraManager theCamera;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         theCamera = FindObjectOfType<CameraManager>();
    13.         thePlayer = FindObjectOfType<PlayerManager>();
    14.         if (startPoint == thePlayer.currentMapName)
    15.         {
    16.             theCamera.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, theCamera.transform.position.z);
    17.             thePlayer.transform.position = this.transform.position;
    18.             this.gameObject.SetActive(false);
    19.         }
    20.     }
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.     }
    25. }
     

    Attached Files:

    Last edited: Jul 20, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    You may edit your post above.

    Generally scenes are all different, unrelated to each other unless you do something.

    You can put invisible GameObjects in a scene to indicate places such as "Spawn player here" or "Spawn enemies here"
     
  3. FreeJus

    FreeJus

    Joined:
    Feb 9, 2022
    Posts:
    2
    I edited the post thank you.