diff --git a/Assets/Scripts/KerstSpecial/RaceController.cs b/Assets/Scripts/KerstSpecial/RaceController.cs index 78cf93e1..aafc7054 100644 --- a/Assets/Scripts/KerstSpecial/RaceController.cs +++ b/Assets/Scripts/KerstSpecial/RaceController.cs @@ -69,6 +69,7 @@ public class RaceController : MonoBehaviour public GameObject scoreBoard; public List skateSounds = new List(); + private AudioSource skateSource; private void Start() { @@ -176,6 +177,20 @@ private void InitPlayer() WeatherAnimator = this.GetComponent(); WeatherAnimator.SetBool("Storm", false); PlayerAnimator.SetBool("OnIce", true); + + skateSource = player.AddComponent(); + skateSource.loop = false; + } + + void PlayRandomClip() + { + int index = UnityEngine.Random.Range(0, skateSounds.Count - 1); + if (skateSource.isPlaying) + return; + + skateSource.clip = skateSounds[index]; + skateSource.pitch = Mathf.Clamp(playerMoveVector.magnitude / 1000f, 1, 5); + skateSource.Play(); } public void ResetPlayer() @@ -320,6 +335,10 @@ private void Update() } } + if(playerMoveVector.magnitude / 1000 > 0.5f) + { + PlayRandomClip(); + } camYawDelta = Mathf.Lerp(camYawDelta, rotationDelta, Time.deltaTime * rotationSpeed); if (Mathf.Abs(camYawDelta) > 0.02f)