I try to rotate camera of my player, but the code below are don’t work. I use it it my save/load game functionality
public void ButtonSave()
{
PlayerPrefs.SetFloat("transform position x" + currentActiveSlot, playerTransform.position.x);
PlayerPrefs.SetFloat("transform position y" + currentActiveSlot, playerTransform.position.y);
PlayerPrefs.SetFloat("transform position z" + currentActiveSlot, playerTransform.position.z);
PlayerPrefs.SetFloat("transform rotation x" + currentActiveSlot, playerTransform.rotation.x);
PlayerPrefs.SetFloat("transform rotation y" + currentActiveSlot, playerTransform.rotation.y);
PlayerPrefs.SetFloat("transform rotation z" + currentActiveSlot, playerTransform.rotation.z);
PlayerPrefs.Save();
}
public void ButtonLoad() // call via canvas UI load button
{
// this work
playerTransform.position = new Vector3(
PlayerPrefs.GetFloat("transform position x" + currentActiveSlot),
PlayerPrefs.GetFloat("transform position y" + currentActiveSlot),
PlayerPrefs.GetFloat("transform position z" + currentActiveSlot));
// this don't work
playerTransform.localEulerAngles = new Vector3(
PlayerPrefs.GetFloat("transform rotation x" + currentActiveSlot),
PlayerPrefs.GetFloat("transform rotation y" + currentActiveSlot),
PlayerPrefs.GetFloat("transform rotation z" + currentActiveSlot));
}
Tried combinations below, but they don’t work too
playerTransform.Rotate(new Vector3(1, 2, 3));
playerTransform.Rotate(1, 2, 3);
playerTransform.eulerAngles = new Vector3(1, 2, 3);