using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CheckpointController : MonoBehaviour
{
    public Transform checkpointFlag;
    public Vector3 checkpointFlagOffset;
    public Vector3 savedPosition;
    public Quaternion savedRotation;

    public Movement playerMovement;
    public float checkpointCooldown;
    public float timeSinceLastCheckpoint;



    // Update is called once per frame
    void Update()
    {
        timeSinceLastCheckpoint += Time.deltaTime;

        if (timeSinceLastCheckpoint >= checkpointCooldown)
        {

            if (Input.GetKeyDown(KeyCode.F5))
            {
                checkpointFlag.position = transform.position + checkpointFlagOffset;
                checkpointFlag.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
                savedPosition = transform.position;
                savedRotation = transform.rotation;
            }
            
        }

        if (Input.GetKeyDown(KeyCode.F6))
        {
            Debug.Log("quicksave loaded");
            playerMovement.velocity = Vector3.zero;
            playerMovement.characterController.enabled = false;
            
            transform.position = savedPosition;
            //transform.rotation = savedRotation;
            playerMovement.characterController.enabled = true;
        }


        if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

    }
}
