I need to save my camera rotation (from MouseLook.cs) I use this script :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class QuickSave : MonoBehaviour
{
public string fileName = "QuickSave";
[System.Serializable]
class PR
{
public float MRX;
public float MRY;
}
public void Save(){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = new FileStream(Application.persistentDataPath +"/"+ "SaveFile", FileMode.Create);
PR newData = new PR();
newData.MRX=GetComponent<MouseLook>().xRot ;
newData.MRY=GetComponent<MouseLook>().yRot ;
bf.Serialize(file, newData);
file.Close();
}
public void Load(){
if (File.Exists(fileName)){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = new FileStream(Application.persistentDataPath +"/"+ "SaveFile", FileMode.Open,FileAccess.Read);
PR newData1 = (PR)bf.Deserialize(file);
GetComponent<MouseLook>().xRot = newData1.MRX;
GetComponent<MouseLook>().yRot = newData1.MRY;
file.Close();
}
}
void LateUpdate () {
if (Input.GetKey (KeyCode.F5))
{
Save();
}
if (Input.GetKey (KeyCode.F9))
{
Load();
}
}
}
}
When I Save rotation I get ERROR:
ArgumentException: GetComponent requires that the requested component ‘MouseLook’ derives from MonoBehaviour or Component or is an interface.
When I Load rotation I get ERROR:
SerializationException: serializationStream supports seeking, but its length is 0