2021-01-06 16:10:11 +01:00
|
|
|
using System;
|
2021-01-11 03:13:03 +01:00
|
|
|
using Ktyl.Util;
|
2021-01-06 16:10:11 +01:00
|
|
|
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-11 03:13:03 +01:00
|
|
|
[SerializeField] private int[] onBarBeats;
|
|
|
|
[SerializeField] private int beatWait;
|
|
|
|
|
2021-01-10 16:20:28 +01:00
|
|
|
[SerializeField] private float xMin = -10;
|
|
|
|
[SerializeField] private float xMax = 10;
|
2021-01-06 16:10:11 +01:00
|
|
|
|
2021-01-11 03:13:03 +01:00
|
|
|
[SerializeField] private SerialFloat _playerXPosition;
|
|
|
|
[SerializeField] private SerialFloat _playerZPosition;
|
|
|
|
|
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-11 03:13:03 +01:00
|
|
|
_shoot = false;
|
|
|
|
for (int i = 0; i < onBarBeats.Length; i++)
|
|
|
|
{
|
|
|
|
var barBeat = onBarBeats[i];
|
|
|
|
|
|
|
|
_shoot = (beat + barBeat) % beatWait == 0;
|
|
|
|
if (_shoot) break;
|
|
|
|
}
|
|
|
|
|
2021-01-10 16:20:28 +01:00
|
|
|
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-11 03:13:03 +01:00
|
|
|
// var playerPosition = Vector3.right * _playerXPosition;
|
|
|
|
// Vector3.forward * _playerZPosition;
|
|
|
|
// transform.LookAt(playerPosition);
|
2021-01-06 16:10:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsShooting()
|
|
|
|
{
|
|
|
|
if (!_shoot) return false;
|
|
|
|
|
|
|
|
_shoot = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|