Scriptum/Assets/Scripts/PlayerPosition.cs

51 lines
1.5 KiB
C#
Raw Permalink Normal View History

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);
}
2022-12-06 01:20:01 +01:00
public static Vector3 LoadPosition()
{
2022-12-06 01:20:01 +01:00
var x = PlayerPrefs.GetFloat("player.position.x");
var y = PlayerPrefs.GetFloat("player.position.y");
var z = PlayerPrefs.GetFloat("player.position.z");
2022-12-06 01:20:01 +01:00
return new Vector3(x, y, z);
}
2023-01-05 01:30:01 +01:00
2022-12-06 01:20:01 +01:00
/// <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()
{
2022-12-06 01:20:01 +01:00
if (OnMapAppearanceMethod.IsJustLaunched())
{
2022-12-06 01:20:01 +01:00
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;
}
}
2022-12-06 01:20:01 +01:00
}