Question by
Rodogs · Jul 25, 2016 at 03:16 PM ·
c#javascript
Loading saved location from a .cs file in my main menu which is a .js file.
Alright, so my main menu is called 'TitleButtons.js', the code is below:
import UnityEngine.SceneManagement;
function OnGUI() {
if (GUI.Button (Rect (Screen.width/2-550, Screen.height/2-130, 300, 30), "Start A New Adventure")) {
SceneManager.LoadScene(1);
}
if (GUI.Button (Rect (Screen.width/2-550, Screen.height/2-90, 300, 30), "Load Previous Adventure")) {
**//insert code to load savegame here.**
}
if (GUI.Button (Rect (Screen.width/2-550, Screen.height/2-10, 300, 30), "Exit")) {
SceneManager.Quit ();
} }
Here is my SaveGame.cs file, which saves the position:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SaveGame : MonoBehaviour {
public Transform Player;
public void Awake()
{
Vector3 newPosition = Vector3.zero;
newPosition.x = PlayerPrefs.GetFloat("x");
newPosition.x = PlayerPrefs.GetFloat("y");
newPosition.x = PlayerPrefs.GetFloat("z");
newPosition.x = PlayerPrefs.GetFloat("Cam_y");
}
public void SaveGameSettings(bool Quit)
{
PlayerPrefs.SetFloat("x", Player.position.x);
PlayerPrefs.SetFloat("y", Player.position.y);
PlayerPrefs.SetFloat("z", Player.position.z);
PlayerPrefs.SetFloat("Cam_y", Player.eulerAngles.y);
if (Quit)
{
Time.timeScale = 1;
SceneManager.LoadScene("TitleScreen");
}
}
}
So my question is, what would i put in the 'insert code to load savegame here' bit, found at the second GUI.button to load the Awake() function within SaveGame.cs.
Please, if you could explain the solution as detailed as possible, I'd appreciate it as I'm very keen to learn! Thank-you so much for your time, and your attempts to help me! :)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612085505im_/https://answers.unity.com/themes/thub/images/avi.jpg)