- Home /
Multiple Start points
I am creating a 2d rpg game and I want to create multiple start points so that the character starts in a certain spot and after going into a house(changing scene) and coming back (changing back to first scene), starts outside of the house instead of where the player started the game. I am new to c# but I do have programming knowledge (I have only used c++ prior to this). How would I go about doing this? Thanks in advance!
Answer by herDev · Feb 08, 2017 at 10:20 AM
On a really basic level, you could create a public class with a public static variable that can be accessed across scenes. You can set the variable when the character enters the building. Then you could check against that variable when the First Scene loads and position accordingly.
public class PlayerData: MonoBehaviour
{
public static int spawnLocation = 0;
}
public class FirstScene : MonoBehaviour
{
void Start()
{
switch (PlayerData.spawnLocation)
{
case 1:
//Position player location one
break;
case 2:
//Position player location two
break;
default:
//initial start location;
break;
}
}
}
Your answer
Follow this Question
Related Questions
Rigidbody2D.MovePosition is not being instaneous 0 Answers
How can i trigger death , set spawnpoints & add music? ( 2D ) 1 Answer
respawn all after player die or doing checkpoint 1 Answer
how retrieve final player position in previous scene after switching from a new scene? in 2d rpg 4 Answers
Start points don't work when I switch from the title screen, to the playable scene 0 Answers