Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Player Prefs not setting the position at start of the game

$
0
0
Hi I have a main menu where I delete my player prefs, and then at my level 1 I set up the player position by getting the float and writing it in the start function. Vector3 newPos = new Vector3(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"), PlayerPrefs.GetFloat("PlayerZ")); player.gameObject.transform.position = newPos; the script which save the positions to player prefs is as follows which I wrote at other script in the start functio: GameMaster.gm.spawnPoint.position = checkpoints[value].transform.position; PlayerPrefs.SetFloat("PlayerX", GameMaster.gm.spawnPoint.position.x); PlayerPrefs.SetFloat("PlayerY", GameMaster.gm.spawnPoint.position.y); PlayerPrefs.SetFloat("PlayerZ", GameMaster.gm.spawnPoint.position.z); PlayerPrefs.Save(); the problem is when I came from main menu which deletes the player prefs and I load level 1, the player's position is set up at 0,0,0 axis. I think the problem here is the player prefs not setting up at the start function, I tried writing it at the update, but the player's position will be stuck because it is called once per frame. Any help would be highly appreciated! Thank in advance

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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