Last year player prefs was a pain, since we was new to it, now that we've worked with it some more were a little more comfortable with it, this year we will purely need it for saving the players location when entering a building as they'll be existing through the same position.
private var PlayerX : float; private var PlayerY : float; 5.private var PlayerZ : float; var PlayerPosition : Transform; var player : GameObject;10. function Update(){ //=======Setting Player position for save==== 15.PlayerX =(PlayerPosition.transform.position.x); PlayerY =(PlayerPosition.transform.position.y); PlayerZ =(PlayerPosition.transform.position.z);20. //=====Press "K" key to save position.================ if (Input.GetKeyUp ("k")){ 25. saveAttributes(); } //=====Press "L" key to load position.================30. if (Input.GetKeyUp ("l")){ loadstuff(); 35. } } 40.//saving playerPrefs function saveAttributes() { PlayerPrefs.SetFloat("PlayerX",PlayerPosition.transform.position.x);45. PlayerPrefs.SetFloat("PlayerY",PlayerPosition.transform.position.y); PlayerPrefs.SetFloat("PlayerZ",PlayerPosition.transform.position.z); 50.} function loadstuff () { 55.PlayerPosition.transform.position.x = (PlayerPrefs.GetFloat("PlayerX")); PlayerPosition.transform.position.y = (PlayerPrefs.GetFloat("PlayerY")); PlayerPosition.transform.position.z = (PlayerPrefs.GetFloat("PlayerZ"));60. }Labels: Cameron
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home