mirror of
https://github.com/Steffo99/beat-td.git
synced 2024-11-23 15:54:18 +00:00
31 lines
690 B
C#
31 lines
690 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class InstantiateOnBeat : MonoBehaviour {
|
|||
|
|
|||
|
public GameObject target;
|
|||
|
public float beats;
|
|||
|
|
|||
|
private float period;
|
|||
|
private float cooldown;
|
|||
|
private SongData songData;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
songData = GameObject.FindGameObjectWithTag("GameController").GetComponent<SongData>();
|
|||
|
period = beats * 60 / songData.bpm;
|
|||
|
cooldown = period;
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
cooldown -= Time.deltaTime;
|
|||
|
if (cooldown <= 0)
|
|||
|
{
|
|||
|
Instantiate(target, transform.position, transform.rotation);
|
|||
|
cooldown = period;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|