Scriptum/Assets/Scripts/PlayerPosition.cs

47 lines
1004 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("x", x);
PlayerPrefs.SetFloat("y", y);
PlayerPrefs.SetFloat("z", z);
}
public void LoadPosition()
{
x = PlayerPrefs.GetFloat("x");
y = PlayerPrefs.GetFloat("y");
z = PlayerPrefs.GetFloat("z");
Vector3 LoadPosition = new Vector3(x, y, z);
transform.position = LoadPosition;
}
void Start()
{
if (PlayerPrefs.GetInt("continued") == 1)
{
LoadPosition();
StartCoroutine(ChangeContinueValue());
}
}
private IEnumerator ChangeContinueValue()
{
yield return new WaitForSeconds(0.2f);
PlayerPrefs.SetInt("continued", 0);
}
}