- Home /
Loading player location in the same scene
i've been working on a game lately and i stumbled on a problem and that is loading my player from a platform to another , for example when he is done running trough the first platform from start to the end he will automatically jump to another and he is an example of the map :
and i have every platform on a totally different scene separated;
so pls does any one have a good idea on how to load the player in each platform after we run trough it ;
thanks for your consideration and your time;
How about a Spawn point at Begin and a Box Collider at the end with OnTriggerEnter load new scene?
You would want to make a player object into a prefab
then make an empty game object and make it into a prefab called spawnPoint
then make this script
Public Transform player;
Public Transfrom spawnPoint;
void Start()
{
Instantiate(player, spawnPoint.position, spawnPoint.rotation);
}
the Start Function runs once when the object is created (wich is when a scene is loaded or object is instantiated)
so by attaching this script to the levels of you scenes and dropping in the appropraite prefabs, it will spawn the player at the spawn point when the scene begins.
i m gratefully thankful for everyone ho answered my question , thank you ^^
Answer by kimardamina · Aug 18, 2015 at 04:33 PM
Was also thinking you just add triggers and make it instantiates on the next point and you save that point for the next time you open the same scene if you are putting everything on one same scene.
i used triggers as you said and it work perfectly except that he face the wrong direction when he get teleported from a position to other i tried using this line of code :
player.transfrom.rotation = destination.transform.rotation ;
but is does nit seem to work :/
Answer by Youri1er · Aug 18, 2015 at 02:21 PM
Yes that's easy, you put an empty object at the start of your platform. You name it start.
On a empty object you put a script "spawnManager" in each scene. The spawn Manager script looks like this:
public class Spawn_Manager : MonoBehaviour
{
public GameObject Start_Spawn;
public GameObject Player_Prefab;
// Use this for initialization
void Start ()
{
if(Start_Spawn != null)
{
GameObject.Instantiate(Player_Prefab,Start_Spawn.transform.position,Quaternion.identity);
}
else
Debug.Log("Please set a start spawn point");
}
}
And at the end you have many option. You put a collider or trigger at the end to detect when he go in and Application.Loadlevel.
Or you make a second empty object at the end. And you make a distance test to know if you are next to him. and then Application.Loadlevel.
This works because when you Application.Loadlevel, in each scene SpawnManager instantiate the playerPrefab to the startEmptyPoint. You can make multiple spawnStart and choose a random number to select one of these, etc.
Answer by Runalotski · Aug 18, 2015 at 02:29 PM
You would want to make a player object into a prefab
then make an empty game object and make it into a prefab called spawnPoint
then make this script
Public Transform player;
Public Transfrom spawnPoint;
void Start()
{
Instantiate(player, spawnPoint.position, spawnPoint.rotation);
}
the Start Function runs once when the object is created (wich is when a scene is loaded or object is instantiated)
so by attaching this script to the levels of your scenes and dropping in the appropraite prefabs, it will spawn the player at the spawn point when the scene begins.