2021-01-05 18:13:29 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using DG.Tweening;
|
|
|
|
using UnityEngine;
|
|
|
|
using Random = UnityEngine.Random;
|
|
|
|
|
|
|
|
public class MoveAfterDelay : MonoBehaviour
|
|
|
|
{
|
2021-01-06 16:10:11 +01:00
|
|
|
[SerializeField] private int beatsBeforeMove = 16;
|
|
|
|
[SerializeField] private float scaleAmount = 1.5f;
|
|
|
|
[SerializeField] private int numBeatsAfterScale = 4;
|
|
|
|
|
|
|
|
private static AudioBeatManager _audio;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (_audio == null)
|
|
|
|
_audio = FindObjectOfType<AudioBeatManager>();
|
|
|
|
}
|
|
|
|
|
2021-01-05 18:13:29 +01:00
|
|
|
private void OnEnable()
|
|
|
|
{
|
2021-01-06 16:10:11 +01:00
|
|
|
_audio.OnBeatEvent += AudioOnBeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
_audio.OnBeatEvent -= AudioOnBeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AudioOnBeat(int beat)
|
|
|
|
{
|
|
|
|
if (beat % beatsBeforeMove != 0) return;
|
|
|
|
|
|
|
|
DOTween.Sequence()
|
|
|
|
.Append(transform.DOScale(Vector3.one * scaleAmount, _audio.TimeBetweenBeats*16).SetEase(Ease.InQuint))
|
|
|
|
.Append(transform.DOScale(Vector3.one, _audio.TimeBetweenBeats*16).SetEase(Ease.OutQuint))
|
|
|
|
.Append(transform.DOMoveZ(-30, 1.0f).SetEase(Ease.InOutQuint).SetDelay(_audio.TimeBetweenBeats * numBeatsAfterScale))
|
|
|
|
.Play();
|
2021-01-05 18:13:29 +01:00
|
|
|
}
|
2021-01-06 16:10:11 +01:00
|
|
|
}
|