Scriptum/Assets/Scripts/RespawnScript.cs

31 lines
888 B
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RespawnScript : MonoBehaviour
{
private string currentScene;
public GameObject mainCh;
public FloatValue maxHealth;
public void RespawnOnCurrentScene()
{
mainCh = GameObject.FindGameObjectWithTag("Player");
Scene scene = SceneManager.GetActiveScene();
currentScene = scene.name;
SceneManager.LoadScene(currentScene);
2023-01-05 21:22:35 +01:00
Player player = mainCh.GetComponent<Player>();
2023-01-05 21:22:35 +01:00
// 1. health
player.currentHealth = PlayerPrefs.GetFloat("maxHealth");
PlayerPrefs.SetFloat("health", PlayerPrefs.GetFloat("maxHealth"));
PlayerPrefs.SetFloat("health-S", PlayerPrefs.GetFloat("maxHealth"));
// 2. exp & lvl
player.ManageLevels(PlayerPrefs.GetFloat("exp-S"));
}
}