O
O
Ostap242022-03-18 21:51:39
Unity
Ostap24, 2022-03-18 21:51:39

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

1 answer(s)
F
freeExec, 2022-03-18
@Ostap24

yes, unity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question