﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class LevelComplete : MonoBehaviour
{
    private bool levelCompleted = false;

    public delegate void OnLevelCompleted();
    public static event OnLevelCompleted LevelCompleted;
    

    private void OnTriggerEnter(Collider other)
    {
        if (levelCompleted)
            return;

        if(other.transform.root.GetComponent<RCC_CarControllerV3>())
        {
            levelCompleted = true;
            LevelCompleted?.Invoke();
            GameSettings.PlayerCar.canControl = false;
            float wait = 0.15f;

            print(wait);
            Invoke(nameof(StopCar), wait);

        }

    }

    void StopCar()
    {
        GameSettings.PlayerCar.rigid.velocity = Vector3.zero;
    }
}
