Quantcast
Channel: Latest Questions by Himani_123
Viewing all articles
Browse latest Browse all 54

how to save and load the game state

$
0
0
i want to save the game state and want to load it on resume button click.But i dont knw how to do that.,i tried the snippet using UnityEngine; using System.Collections; public class SaveState : MonoBehaviour { // Use this for initialization void Start () { Load (); } // Update is called once per frame void Update () { } void Load(){ if (PlayerPrefs.GetFloat ("x") != null) { transform.position= new Vector3(PlayerPrefs.GetFloat("x"),PlayerPrefs.GetFloat("y"),PlayerPrefs.GetFloat("z")); } transform.position = new Vector3 (transform.position.x, transform.position.y, transform.position.z); Save (); } void Save() { PlayerPrefs.SetFloat("x",transform.position.x); PlayerPrefs.SetFloat("y",transform.position.y); PlayerPrefs.SetFloat("z",transform.position.z); } } when i attach it to my new game script,after closing when i again click on new game,cubes in my game get displace and also texture i attach to the cubes donot load. why this happen..?? what am i doing wrong ??

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>