Hey everyone, ive been having trouble loading player positions between scenes. What i have now is an overworld with buildings you can enter, each being a seperate sene, with a trigger that returns you to the over world. What I would like to happen is that when the overworld scene loads, the player is place outside of the building they just exited, however the player keeps being placed at the starting point for the overworld scene. Heres what i have now.
this script is placed on the trigger that sends them to the building interior
sing UnityEngine;
using System.Collections;
public class NewLevelChange : MonoBehaviour {
public GameObject player;
//public LevelManager levelManager;
void Start () {
player = GameObject.Find("Player");
}
void Update () {
}
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == "Player"){
PlayerPrefs.SetFloat("PlayerX",player.transform.position.x);
PlayerPrefs.SetFloat("PlayerY", player.transform.position.y);
PlayerPrefs.SetFloat("PlayerZ", player.transform.position.z);
Application.LoadLevel("Level2");
}
}
}
and this is the script that should return them to the correct place in the overworld.
public var player : GameObject;
//var newPosition = Vector3(0,0,0);
function Start () {
player = GameObject.Find(“Player”);
}
function Update () {
}
function OnTriggerEnter(col : Collider){
Application.LoadLevel(“City”);
var newX :float = PlayerPrefs.GetFloat(“PlayerX”);
var newY :float = PlayerPrefs.GetFloat(“PlayerY”);
var newZ :float = PlayerPrefs.GetFloat(“PlayerZ”);
Application.LoadLevel("City");
player.transform.position = Vector3(newX,newY,newZ);
}
I’m rather new to Unity scripting so it’s probably some simple mistake, but any help or advice would be greatly appreciated