Answer the question
In order to leave comments, you need to log in
Error CS1061: 'GameObject' ps Is this a unit?
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?)
script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class Save : MonoBehavior {
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, position);
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();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question