Hi,
I downloaded the ArrayPrefs2 script for saving the rotation of an object in my game. But it doesn work!
I tried a couple of things but nothing seems to happen…
The following code is how it is explained on http://wiki.unity3d.com/index.php/ArrayPrefs2
function Save()
{
if (!PlayerPrefsX.SetQuaternion ("Ring1Rotation", this.transform.rotation))
print ("Saving rotation failed");
}
function Load()
{
this.transform.rotation= PlayerPrefsX.GetQuaternion ("Ring1Rotation", Quaternion.Euler(90, 45, 0));
}
I also tried this because the object is a child from another object
function Save()
{
if (!PlayerPrefsX.SetQuaternion ("Ring1Rotation", this.transform.localRotation))
print ("Saving rotation failed");
}
function Load()
{
this.transform.localRotation= PlayerPrefsX.GetQuaternion ("Ring1Rotation", Quaternion.Euler(90, 45, 0));
}
and this
function Save()
{
PlayerPrefsX.SetQuaternion ("Ring1Rotation", this.transform.rotation);
}
function Load()
{
this.transform.rotation= PlayerPrefsX.GetQuaternion ("Ring1Rotation");
}
and some other combinations that look like this. But nothing seems to work.
It is 100% sure not my saving code, cause I left alot of variables out, which are saved in the same functions and they work perfectly.
Thanks in advance for any advice!
Alexander Sarton
You could try this one. It save and load position rotation once per frame. You could attach it to an empty object.
using UnityEngine;
using System.Collections;
public class YOURCLASS : MonoBehaviour {
public static GameObject player;
// Use this for initialization
void Start() {
player = GameObject.Find("YOUROBJECT");
player.transform.position = new Vector3 (PlayerPrefs.GetFloat("PlayerPositionX"), 5, PlayerPrefs.GetFloat("PlayerPositionZ"));
player.transform.rotation = Quaternion.Euler (new Vector3(0, PlayerPrefs.GetFloat("PlayerRotationY"), 0));
}
// Update is called once per frame
void Update() {
SaveDataPosition();
SaveDataRotation();
}
public static void SaveDataPosition() {
PlayerPrefs.SetFloat("PlayerPositionX", playerposition.player.transform.position.x);
PlayerPrefs.SetFloat("PlayerPositionY", playerposition.player.transform.position.y);
PlayerPrefs.SetFloat("PlayerPositionZ", playerposition.player.transform.position.z);
}
public static void SaveDataRotation() {
PlayerPrefs.SetFloat("PlayerRotationX", playerposition.player.transform.eulerAngles.x);
PlayerPrefs.SetFloat("PlayerRotationY", playerposition.player.transform.eulerAngles.y);
PlayerPrefs.SetFloat("PlayerRotationZ", playerposition.player.transform.eulerAngles.z);
}
}
Thanks alot! Your solution worked!
But I did some small things wrong in the editor which might also have effected the reason I created this topic. So Im not sure if it is now working because of your code or my stupidity in the editor. But thanks anyway, your script works good 
I coded it for my project. It works like charm.