Scriptum/Assets/Scripts/PlayerPosition.cs

40 lines
930 B
C#
Raw 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);
}
public void LoadPosition()
{
x = PlayerPrefs.GetFloat("player.position.x");
y = PlayerPrefs.GetFloat("player.position.y");
z = PlayerPrefs.GetFloat("player.position.z");
Vector3 LoadPosition = new Vector3(x, y, z);
transform.position = LoadPosition;
}
void Start()
{
if (OnMapAppearanceMethod.Gateway == OnMapAppearanceMethodEnum.LoadGame)
{
LoadPosition();
}
}
}