WinterJamSnowman/Assets/Scripts/EntityScripts/BoardVisuals.cs

46 lines
1.0 KiB
C#
Raw Normal View History

2023-01-30 16:21:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lemon.GenericLib.VFX;
public class BoardVisuals : MonoBehaviour
{
[Header("Runtime")]
[Space]
[Header("Refereces")]
[SerializeField] private float shakeDuration = 0.1f;
private GameBoard gameBoard;
private CameraController cameraController;
private bool initialized = false;
private void CheckInit()
{
if (!initialized)
{
//initialization code here
gameBoard = GetComponent<GameBoard>();
cameraController = CameraController.instanceCC;
gameBoard.onDrop += shakeOnDrop;
initialized = true;
}
}
private void Start()
{
CheckInit();
}
private void OnDestroy()
{
CheckInit();
gameBoard.onDrop -= shakeOnDrop;
}
private void shakeOnDrop() {
CheckInit();
if (gameBoard.controlledByPlayer) cameraController?.ApplyScreenShake(shakeDuration, true);
}
}