我尝试旋转播放器的相机,但下面的代码不起作用。我用它来保存/加载游戏功能
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);
// Save all 4 values for the quaternion
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.SetFloat("transform rotation w" + currentActiveSlot, playerTransform.rotation.w);
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
Quaternion savedRotation = new Quaternion(
PlayerPrefs.GetFloat("transform rotation x" + currentActiveSlot),
PlayerPrefs.GetFloat("transform rotation y" + currentActiveSlot),
PlayerPrefs.GetFloat("transform rotation z" + currentActiveSlot),
PlayerPrefs.GetFloat("transform rotation w" + currentActiveSlot));
playerTransform.rotation = savedRotation;
}
尝试下面的组合,但它们也不起作用
playerTransform.Rotate(new Vector3(1, 2, 3));
playerTransform.Rotate(1, 2, 3);
playerTransform.eulerAngles = new Vector3(1, 2, 3);
开始模拟后,我无法用手旋转
EDIT1