Assets\Scripts\Save.cs(39,24): error CS1061: 'GameObject' does not contain a definition for 'position' and no accessible extension method 'position' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)
скрипт:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class Save : MonoBehaviour {
public GameObject player;
[System.Serializable]
public class position
{
public float x;
public float y;
public float z;
}
public void save() {
position posi = new position ();
posi.x = player.transform.position.x;
posi.y = player.transform.position.y;
posi.z = player.transform.position.z;
if(!Directory.Exists(Application.dataPath + "/save"))
{
Directory.CreateDirectory(Application.dataPath + "/save");
FileStream f = new FileStream(Application.dataPath + "/save/s.sv", FileMode.Create);
BinaryFormatter form = new BinaryFormatter();
form.Serialize (f, posi);
f.Close ();
}
}
public void Load()
{
if(File.Exists (Application.dataPath + "/save/s.sv")) {
FileStream f = new FileStream(Application.dataPath + "/save/s.sv", FileMode.Open);
BinaryFormatter form = new BinaryFormatter ();
try {
position pos = (position)form.Deserialize (f);
player.position.transform = new Vector3(pos.x, pos.y, pos.z);
}
catch(System.Exception a)
{
Debug.Log(a.Message);
}
finally
{
f.Close();
}
} else
{
Application.Quit ();
}
}
}