2021-01-06 16:10:11 +01:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Scripting;
|
2021-01-10 16:20:28 +01:00
|
|
|
using Random = UnityEngine.Random;
|
2021-01-06 16:10:11 +01:00
|
|
|
|
|
|
|
public class BeatSpawner : ShootInputBase
|
|
|
|
{
|
2021-01-10 16:20:28 +01:00
|
|
|
[SerializeField] private int spawnOnBeat = 2;
|
|
|
|
[SerializeField] private float xMin = -10;
|
|
|
|
[SerializeField] private float xMax = 10;
|
2021-01-06 16:10:11 +01:00
|
|
|
|
|
|
|
private AudioBeatManager _audio;
|
|
|
|
|
|
|
|
private bool _shoot;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
_audio = FindObjectOfType<AudioBeatManager>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnBeat(int beat)
|
|
|
|
{
|
2021-01-10 16:20:28 +01:00
|
|
|
_shoot = beat % spawnOnBeat == 0;
|
|
|
|
if (_shoot)
|
2021-01-10 17:51:34 +01:00
|
|
|
transform.position = new Vector3(Mathf.Lerp(xMin, xMax, Mathf.Sin(beat)), transform.position.y, transform.position.z);
|
2021-01-06 16:10:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsShooting()
|
|
|
|
{
|
|
|
|
if (!_shoot) return false;
|
|
|
|
|
|
|
|
_shoot = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|