@Ostap24

Error CS1061: 'GameObject' p.s. ето юнити?

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 ();
}
}
}
  • Вопрос задан
  • 39 просмотров
Решения вопроса 1
freeExec
@freeExec
Участник OpenStreetMap
Да, юнити
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы