using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMaster : MonoBehaviour
{
private static GameMaster instance;
public Vector2 lastCheckPointPos;
void Awake()
{
if(instance == null)
{
instance = this;
DontDestroyOnLoad(instance);
}
else
{
Destroy(gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Checkpoint : MonoBehaviour
{
private GameMaster gm;
void Start()
{
gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
gm.lastCheckPointPos = transform.position;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerPos : MonoBehaviour
{
private GameMaster gm;
void Start()
{
gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = gm.lastCheckPointPos;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}