FireDrago19
@FireDrago19

Save Game в Unity. Не возвращает координаты. Как установить объекту координаты?

Скачал с Unity Assets SaveGame
Вроде все сохраняет при выходе и восстанавливает при запуске но не расположение объектов(Появляются в нулевых координатах)(Сделал сохранение не Vector3 а отдельно каждую потому что не могу потом сделать new Vector3)
using UnityEngine;
using System.Collections;
using System.Linq;

public class SaveSystemSetup : MonoBehaviour {

	[SerializeField] private string fileName = "Profile.bin"; // file to save with the specified resolution
    [SerializeField] private bool dontDestroyOnLoad; // the object will move from one scene to another (you only need to add it once)

	public GameObject towerprefab;
	public int i, b;
	public string namee, level, xc, yc, zc;
	void Awake()
	{
		SaveSystem.Initialize(fileName);
		if (dontDestroyOnLoad) DontDestroyOnLoad(transform.gameObject);
		i = SaveSystem.GetInt("Numboftower");
		b = 0; 
		while (b < i)
		{
			namee = "coord" + b.ToString();
			level = "level" + b.ToString();
			xc = "x" + b.ToString();
			yc = "y" + b.ToString();
			zc = "z" + b.ToString();
			GameObject proj = Instantiate(towerprefab);
			proj.transform.position = new Vector3(SaveSystem.GetFloat(xc), SaveSystem.GetFloat(yc), SaveSystem.GetFloat(zc));
			proj.GetComponent<DiceLVL>().LVL = SaveSystem.GetInt(level);
			//proj.GetComponent<DiceLVL>().Dannie = 1;
			b++;
		}
	}
    // if the object is present in all game scenes, auto save before exiting
    // on some platforms there may not be an exit function, see the Unity help
    void OnApplicationQuit()
	{
		SaveSystem.SaveToDisk();
		SaveSystem.SetInt("Numboftower", GameObject.FindGameObjectsWithTag("Tower").Length);
		i = GameObject.FindGameObjectsWithTag("Tower").Length;
		b = 0;
		while (b < i)
		{
			namee = "coord" + b.ToString();
			level = "level" + b.ToString();
			xc = "x" + b.ToString();
			yc = "y" + b.ToString();
			zc = "z" + b.ToString();
			SaveSystem.SetFloat(xc, GameObject.FindGameObjectsWithTag("Tower")[b].transform.position.x);
			SaveSystem.SetFloat(yc, GameObject.FindGameObjectsWithTag("Tower")[b].transform.position.y);
			SaveSystem.SetFloat(zc, GameObject.FindGameObjectsWithTag("Tower")[b].transform.position.z);
			SaveSystem.SetInt(level, GameObject.FindGameObjectsWithTag("Tower")[b].GetComponent<DiceLVL>().LVL);
			b++;
		}
	}
}
  • Вопрос задан
  • 69 просмотров
Решения вопроса 1
AnotherAltr
@AnotherAltr
C# Dev
Не изобретайте костыли. Особенно с кастомными системами сохранений данных, обычно с ними куча проблем на разных платформах.

Для сохранения данных самое простое это:
PlayerPrefs

И не используйте тяжеловестные операции в методе OnApplicationQuit, особенно если он синхронный.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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