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

Unable to set Rotation

$
0
0
I've written a basic script to set the position and rotation of a gameobject with PlayerPrefs. In short, the engine is recognizing the correct values, but when it 'sets' them, the gameObject is always at 0,0,0. No errors or any other warnings. These are apart of the same script, the save part is wrapped in the Update function. The print statement output the correct values, and the position is right. But the rotation is always at 0,0,0. void Start () { //source = this.GetComponent(); print("Setting player pos: " + PlayerPrefs.GetFloat("PositionX") + "," + PlayerPrefs.GetFloat("PositionY") + "," + PlayerPrefs.GetFloat("PositionZ")); print("Setting player rot: " + PlayerPrefs.GetFloat("RotationX") + "," + PlayerPrefs.GetFloat("RotationY") + "," + PlayerPrefs.GetFloat("RotationZ")); if (PlayerPrefs.GetFloat("PositionX") != 0f && PlayerPrefs.GetFloat("PositionY") != 0f && PlayerPrefs.GetFloat("PositionZ") != 0f) //ensure a value has been saved { this.gameObject.transform.position = new Vector3(PlayerPrefs.GetFloat("PositionX"), PlayerPrefs.GetFloat("PositionY"), PlayerPrefs.GetFloat("PositionZ")); //this.gameObject.transform.eulerAngles = new Vector3(PlayerPrefs.GetFloat("RotationX"), PlayerPrefs.GetFloat("RotationY"), PlayerPrefs.GetFloat("RotationZ")); this.gameObject.transform.localRotation = Quaternion.Euler(0,90f,0); } } if(Input.GetKeyDown(KeyCode.T)) { PlayerPrefs.SetFloat("PositionX", this.gameObject.transform.position.x); PlayerPrefs.SetFloat("PositionY", this.gameObject.transform.position.y); PlayerPrefs.SetFloat("PositionZ", this.gameObject.transform.position.z); PlayerPrefs.SetFloat("RotationX", this.gameObject.transform.localEulerAngles.x); PlayerPrefs.SetFloat("RotationY", this.gameObject.transform.localEulerAngles.y); PlayerPrefs.SetFloat("RotationZ", this.gameObject.transform.localEulerAngles.z); print("Setting Rot: " + PlayerPrefs.GetFloat("RotationX") + "," + PlayerPrefs.GetFloat("RotationY") + "," + PlayerPrefs.GetFloat("RotationZ")); // source.clip = save; source.PlayOneShot(save, 1); PlayerPrefs.Save(); }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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