Welcome to stack overflow, and presumably, programming.
What you are looking for, is a way to 'transfer' data between scenes as they switch. Though there is no direct way to transfer data between scene, your desired effect can be done by
- Having a globally accessible Singleton or Static instance.
- When a scene loads, a script will read data from the instance (in your case, it will read to determine the player's starting position)
Static Types
In your case, I recommend using static types, you can look into this blog or this short video.
public static class GlobalData {
// Use an Enum if you need to represent more states,
// or you can setup a more sophisticated state machine if necessary.
public static bool PlayerCameFromStage2 { get; set; }
}
// In your player script...
public class YourPlayerScript: MonoBehaviour {
void Start() {
// Access the global static data here...
if (GlobalData.PlayerCameFromStage2) {
// Move to other starting point...
}
}
}
If you would like to look into singleton, I recommend checking out this youtube video, and then looking into DontDestroyOnLoad
.
As Singleton relies on having a GameObject "store" your data, which will be destroyed whenever you switch scenes by default.
The DontDestroyOnLoad
ensures that the GameObject doesn't get destroyed whenever scenes are switched.
P.S. The programming Jargon you are looking for data persistence
, as you would like some data to persist when changing between scenes. Which you can use said data to check where the player needs to spawn at.