ccl4/blueberryPeak/Assets/Scripts/Wind.cs
2025-06-17 11:10:18 +02:00

64 lines
1.9 KiB
C#

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
public class Wind : MonoBehaviour
{
private GameObject Player;
[SerializeField] float windSpeedStep = 0.1f;
[SerializeField] float initWindSpeed;
private float currentWindSpeed; // Declare and will be initialized in Start
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
currentWindSpeed = initWindSpeed; // Initialize currentWindSpeed
AkSoundEngine.SetRTPCValue("WindSpeed", initWindSpeed);
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("fastWind")) // Using CompareTag is more efficient
{
StartCoroutine(ChangeWindSpeed(90));
Debug.Log("fast");
}
if (other.CompareTag("slowWind"))
{
StartCoroutine(ChangeWindSpeed(20));
Debug.Log("slow");
}
if (other.CompareTag("midWind"))
{
StartCoroutine(ChangeWindSpeed(55));
Debug.Log("mid");
}
}
IEnumerator ChangeWindSpeed(float val)
{
while (!Mathf.Approximately(currentWindSpeed, val))
{
print(val+ " " +currentWindSpeed);
// Move currentWindSpeed towards val by windSpeedStep * Time.deltaTime
currentWindSpeed = Mathf.MoveTowards(currentWindSpeed, val, windSpeedStep * Time.deltaTime);
AkSoundEngine.SetRTPCValue("WindSpeed", currentWindSpeed);
yield return null;
}
// Ensure the value is exactly 'val' when the loop finishes, to prevent minor floating point inaccuracies
currentWindSpeed = val;
AkSoundEngine.SetRTPCValue("WindSpeed", currentWindSpeed);
}
}