48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.VFX;
|
|
using UnityEngine;
|
|
|
|
public class WavzController : MonoBehaviour
|
|
{
|
|
|
|
public float bpm;
|
|
public float beatsPerBar;
|
|
public float barsPerPhrase;
|
|
public float phraseLengthSec;
|
|
public float min;
|
|
public float max;
|
|
|
|
private VisualEffect vfx;
|
|
|
|
void Start() {
|
|
vfx = gameObject.GetComponent<VisualEffect>();
|
|
|
|
min = 0.5f;
|
|
max = 128f;
|
|
|
|
bpm = 120f;
|
|
// assume 4 beats per bar * 8 bars per phrase
|
|
beatsPerBar = 4.0f;
|
|
barsPerPhrase = 8.0f;
|
|
phraseLengthSec = (bpm / 60.0f) * beatsPerBar * barsPerPhrase;
|
|
|
|
Debug.Log($"phrase length in seconds {phraseLengthSec}");
|
|
}
|
|
|
|
void Update() {
|
|
float x = max * Mathf.Abs(Mathf.Sin(Time.time / phraseLengthSec)) + min;
|
|
float y = max * Mathf.Abs(Mathf.Sin( Time.time / (phraseLengthSec / 2))) + min;
|
|
float z = max * Mathf.Abs(Mathf.Sin(Time.time / (phraseLengthSec / 3))) + min;
|
|
vfx.SetFloat("AttractionSpeed", y);
|
|
vfx.SetFloat("AttractionForce", y);
|
|
vfx.SetFloat("StickDistance", z);
|
|
vfx.SetFloat("StickForce", z);
|
|
}
|
|
|
|
public void SetStickiness(float v) {
|
|
// vfx.SetFloat("StickDistance", z);
|
|
// vfx.SetFloat("StickForce", z);
|
|
}
|
|
}
|