summaryrefslogtreecommitdiff
path: root/ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs
+ init
Diffstat (limited to 'ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs')
-rw-r--r--ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs b/ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs
new file mode 100644
index 0000000..335a17f
--- /dev/null
+++ b/ROUNDS/SoundImplementation/SoundEnvironmentRigidbody.cs
@@ -0,0 +1,33 @@
+using Sonigon;
+using UnityEngine;
+
+namespace SoundImplementation;
+
+public class SoundEnvironmentRigidbody : MonoBehaviour
+{
+ public SoundEvent soundMoveLoop;
+
+ private Rigidbody2D cachedRigidbody2D;
+
+ private bool soundIsPlaying;
+
+ private SoundParameterIntensity parameterIntensity = new SoundParameterIntensity(0f, UpdateMode.Continuous);
+
+ private void Awake()
+ {
+ cachedRigidbody2D = GetComponent<Rigidbody2D>();
+ }
+
+ private void FixedUpdate()
+ {
+ if (cachedRigidbody2D != null && soundMoveLoop != null)
+ {
+ if (!soundIsPlaying)
+ {
+ soundIsPlaying = true;
+ SoundManager.Instance.Play(soundMoveLoop, base.transform, parameterIntensity);
+ }
+ parameterIntensity.intensity = cachedRigidbody2D.velocity.magnitude;
+ }
+ }
+}