Remembering coordinates from previous level.

Hi,
I am trying to find a script to make the level change into another scene which looks a little bit different. That works out, but I want to change my character into another one. I just grab another character and put it into the 2nd scene. But the problem is that I don’t know where the characters last position was. I had an idea for a script that keeps the coordinates of the character, and with the use of don’tdelete the script ( object with script) would come into the 2nd level. Maybe another script in the 2nd level can use the var of the coordinates, and warp the new character to it’s old position.

I am not very good in scripting, but I don’t have the time to figure this out by myself. I tried to find something, but I really couldn’t find anything.

It would be really great if somebody could help me with this, and I will really appreciate it.

Thanks,
Willie

There are 2 ways: use PlayerPrefab class or implement singleton class to store data bedween scenes. In my opinion 2nd way is better.

Simplest implementation os singleton pattern bellow:
UPD

    class myData
    {
       private static myData instance = null;
       public static myData Instance
       {
          get 
		  { 
			if(instance == null)
				instance = new myData();
			return instance; 
		  }
       }
       public Vector3 LastPosition;
	   
       private myData()
       {
			;
       }
    }
     
    ...
    /// usage Scene 1
    myData.Instance.LastPosition = player.transform.position;
     
    /// usage Scene 2
    player.transform.position = myData.Instance.LastPosition;

Thank you very much!
Do I need to add the mydata script and the usage scene 1 to the character in the 1st scene, and the usage 2 to the char in the 2nd scene? Or how does that work?

Thanks,
Willie

No, you should not add this script to any game object, it is not MonoBehaviour succesor. Just place this file at your project.
UPD: I change code example, there was some errors, sorry)))

I placed the script in my standard assets, but I got a lot of errors.
Unexpected token: myData
Unexpected token: Vector3

Could you help me with this?

Hey, you should not put ALL this code in ONE file.

This is should be placed in one file:

        using UnityEngine;
        class myData
        {
           private static myData instance = null;
           public static myData Instance
           {
              get
              {
                if(instance == null)
                    instance = new myData();
                return instance;
              }
           }
           public Vector3 LastPosition;
           
           private myData()
           {
                ;
           }
        }

But this is example of how to save and read data from any place in your game where you want to do this:

Saving:

        myData.Instance.LastPosition = player.transform.position;

Reading:

        player.transform.position = myData.Instance.LastPosition;

P.S.: “Unexpected token: Vector3” error occurs because you need to add using UnityEngine; directive in the begining of the file (I added it in this example).

Good luck!