IDoNotExist писал(а):SashaNyasha писал(а):IDoNotExist писал(а):После загрузки сцены в ней скрипт PlayerPrefsSave присутствует то? И если да, то как он туда попал? Он заранее был на каком - либо гейм объекте сцены, или пришел туда через DontDestroyOnLoad()?
Через DontDestroyOnLoad
В таком случае, Start у тебя вызовется один раз, на той сцене на которой был изначально этот скрипт, впиши LoadPosition() сразу после LoadScene() и будет тебе счастье.
Снова загружается уровень без позиции игрока
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerPrefsSave : MonoBehaviour {
public Transform CurrentPlayerPosition;
public float xPos;
public float yPos;
public float zPos;
// Use this for initialization
void Start(){
//CurrentPlayerPosition = GameObject.Find ("Player");
}
// Update is called once per frame
void Update () {
}
public void LoadLevel(){
SceneManager.GetSceneByName (PlayerPrefs.GetString ("LostLevel"));
SceneManager.GetSceneByBuildIndex (PlayerPrefs.GetInt ("currentscenesave"));
//SceneManager.LoadScene (PlayerPrefs.GetInt ("currentscenesave"));
SceneManager.LoadScene (PlayerPrefs.GetString ("LostLevel"));
LoadPosition ();
}
public void LoadPosition(){
CurrentPlayerPosition.transform.position = new Vector3 (PlayerPrefs.GetFloat ("XPosition"),
PlayerPrefs.GetFloat ("YPosition"), PlayerPrefs.GetFloat ("ZPosition"));
}
public void savePosition(){
PlayerPrefs.SetFloat ("XPosition", CurrentPlayerPosition.transform.position.x);
PlayerPrefs.SetFloat ("YPosition", CurrentPlayerPosition.transform.position.y);
PlayerPrefs.SetFloat ("ZPosition", CurrentPlayerPosition.transform.position.z);
string scName = SceneManager.GetActiveScene().name;
// PlayerPrefs.SetInt ("currentscenesave",SceneManager.GetActiveScene().buildIndex);
PlayerPrefs.SetString ("LostLevel", scName);
}
}