51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerPosition : MonoBehaviour
|
|
{
|
|
public float x, y, z;
|
|
|
|
public void SavePosition()
|
|
{
|
|
x = transform.position.x;
|
|
y = transform.position.y;
|
|
z = transform.position.z;
|
|
|
|
PlayerPrefs.SetFloat("player.position.x", x);
|
|
PlayerPrefs.SetFloat("player.position.y", y);
|
|
PlayerPrefs.SetFloat("player.position.z", z);
|
|
}
|
|
|
|
public static Vector3 LoadPosition()
|
|
{
|
|
var x = PlayerPrefs.GetFloat("player.position.x");
|
|
var y = PlayerPrefs.GetFloat("player.position.y");
|
|
var z = PlayerPrefs.GetFloat("player.position.z");
|
|
|
|
return new Vector3(x, y, z);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ONE BIG SHIT
|
|
///
|
|
/// First MainCharacterManager create instance with previously remembered gateway coords :)
|
|
/// After that we crate new player instance on scene
|
|
/// And finally: This script is deffaultly assigned to player soo..
|
|
/// its overwrites Player coords depending on condition in function below
|
|
/// </summary>
|
|
void Start()
|
|
{
|
|
if (OnMapAppearanceMethod.IsJustLaunched())
|
|
{
|
|
transform.position = LoadPosition();
|
|
|
|
// I really dont remember if we use this vars anywhere so I just assign new value to make sure I dont break anything :D x = transform.position.x;
|
|
x = transform.position.x;
|
|
y = transform.position.y;
|
|
z = transform.position.z;
|
|
}
|
|
}
|
|
} |