rabidus-test/Assets/Scripts/StartGameSlot.cs

47 lines
1.0 KiB
C#
Raw Normal View History

2023-09-11 15:44:17 +03:00
using BNG;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartGameSlot : MonoBehaviour
{
private SnapZone _snapZone;
private LeanTimer _leanTimer;
private void Awake()
{
_snapZone = GetComponent<SnapZone>();
_leanTimer = GetComponent<LeanTimer>();
}
private void OnEnable()
{
_snapZone.OnSnapEvent.AddListener(OnSnaped);
_snapZone.OnDetachEvent.AddListener(OnDetach);
}
private void OnDisable()
{
_snapZone.OnSnapEvent.RemoveListener(OnSnaped);
_snapZone.OnDetachEvent.RemoveListener(OnDetach);
}
private void OnSnaped(Grabbable grab)
{
string level = grab.GetComponent<MonumentMini>().Info.SceneName;
void LoadSelectedLevel()
{
SceneLoader.Instance.LoadScene(level);
}
_leanTimer.StartTimer(1, 0, 3, LoadSelectedLevel);
}
private void OnDetach(Grabbable grab)
{
_leanTimer.StopTimer();
}
}