Switching between scenes saving and translate to previous position
Not sure if this will work, but not quite sure how to do it. I want to have a door, for lack of a better term, that loads a new level where you can build up your stats a bit, then when you exit you are translated back to where you opened the "door."
The loading levels are not a problem, it's when and where to call the translation function. I had thought of putting it on the doorscript so it saves your new data, loads the level, but if it loaded the level, that function call is gone.
public class DoorScript : MonoBehaviour
{
Vector3 ReturnCoord;
TopPanel tp;
void Start()
{
ReturnCoord.x=-8.78f;
ReturnCoord.y=1.94f;
ReturnCoord.z=20.19f;
}
void OnTriggerEnter()
{
Debug.Log("Trigger Entered!");
tp.GetPlayerData();
Application.LoadLevel("Gym");
}
void OnTriggerExit()
{
Debug.Log("OnTriggerExit!");
}
public void RestorePlayer()
{
tp.playerObject.transform.Translate(ReturnCoord);
tp.GetPlayerData();
}
}
The doorscript is attached to just a game object just to test it and make sure it works. TopPanel is where variables are loaded and saved from a JSON string.
public void Exit()
{
tp.Save();
Application.LoadLevel("2");
ds.RestorePlayer();
}
When you want to leave the scene and return. ds is a reference to the doorscript tp is a reference to TopPanel.
Am I on the right track? If not are there any good tutorials that can walk me through this kind of situation? Thanks All!