Hello, Im trying to make a script to change a player starting position based on a prevously loaded scene, for example.
If I go from the scene 7 to scene 2, I need the player to spawn in the p_PosiblePositions[7] in the sector 2. and if I’m going from the scene 4 to scene 2, the p_PosiblePosition to use should be [4].
I tried using this script I made but, then I realized that the OnLevelWasLoaded only tells the current scene that was loaded, not the previous one.
public GameObject[] p_PosiblePositions;
GameObject player;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
}
void OnLevelWasLoaded(int level)
{
switch (level)
{
case 0:
player.transform.position = p_PosiblePositions[0].transform.position;
break;
case 1:
player.transform.position = p_PosiblePositions[1].transform.position;
break;
case 2:
player.transform.position = p_PosiblePositions[2].transform.position;
break;
case 3:
player.transform.position = p_PosiblePositions[3].transform.position;
break;
case 4:
player.transform.position = p_PosiblePositions[4].transform.position;
break;
case 5:
player.transform.position = p_PosiblePositions[5].transform.position;
break;
case 6:
player.transform.position = p_PosiblePositions[6].transform.position;
break;
case 7:
player.transform.position = p_PosiblePositions[7].transform.position;
break;
}
}
*Each scene has his own individual p_PosiblePositions.
Thanks, in advance!
If I didn’t explained well, please leave a comment!