diff --git a/Assets/Art Assets/Models/RockPile_obstacle.prefab b/Assets/Art Assets/Models/RockPile_obstacle.prefab new file mode 100644 index 0000000..57aae68 --- /dev/null +++ b/Assets/Art Assets/Models/RockPile_obstacle.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a750b698cc75f7dda308750afd674fa45aad95990df9ab8b6e8586a9d794bb4 +size 29993 diff --git a/Assets/Art Assets/Models/RockPile_obstacle.prefab.meta b/Assets/Art Assets/Models/RockPile_obstacle.prefab.meta new file mode 100644 index 0000000..8325c9c --- /dev/null +++ b/Assets/Art Assets/Models/RockPile_obstacle.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8c6aea957cd47ea44bac73fce15ca440 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Art Assets/Models/Tree1 1.prefab b/Assets/Art Assets/Models/Tree1 1.prefab index 58cee14..7cb9d13 100644 --- a/Assets/Art Assets/Models/Tree1 1.prefab +++ b/Assets/Art Assets/Models/Tree1 1.prefab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ad45009d67077c0c24b1caef99ee05303afcb3a54f3908b058e086cf0ef42079 +oid sha256:6493e63bf2ef186df878635ba0de5edf753b280fece533d35021f9356c0b389c size 15008 diff --git a/Assets/Art Assets/Models/Tree1 2.prefab b/Assets/Art Assets/Models/Tree1 2.prefab index 5177373..5e465a2 100644 --- a/Assets/Art Assets/Models/Tree1 2.prefab +++ b/Assets/Art Assets/Models/Tree1 2.prefab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c57e22e7200c8232692858b79667584e8bc646389a4dd293f3dcd93be2c00c0 +oid sha256:f75ae3089299c45b6cff4a788206cfdbdb64ecadb89dadb31219176fcf18aa4b size 16139 diff --git a/Assets/Art Assets/Models/Tree1 3.prefab b/Assets/Art Assets/Models/Tree1 3.prefab index 02571c7..0850527 100644 --- a/Assets/Art Assets/Models/Tree1 3.prefab +++ b/Assets/Art Assets/Models/Tree1 3.prefab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94f85a67bb41ee5f9b3ec215399aa4952c16a9d5373c180948f748a028a60684 +oid sha256:9917176645e47b465cbb75a899c38f42b023df9e0053a91954aaa507e402efd4 size 16728 diff --git a/Assets/Art Assets/Models/Tree1 4.prefab b/Assets/Art Assets/Models/Tree1 4.prefab new file mode 100644 index 0000000..5ac7d7c --- /dev/null +++ b/Assets/Art Assets/Models/Tree1 4.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:990310f128c4968e1e2d504c996f7cc7982d152a4f501be474be6b85630fed6c +size 32240 diff --git a/Assets/Art Assets/Models/Tree1 4.prefab.meta b/Assets/Art Assets/Models/Tree1 4.prefab.meta new file mode 100644 index 0000000..adea22d --- /dev/null +++ b/Assets/Art Assets/Models/Tree1 4.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 27e23f110c0eb104ab4d0ce45e81ac31 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Art Assets/Models/Tree1.prefab b/Assets/Art Assets/Models/Tree1.prefab index 2e5a06e..821d166 100644 --- a/Assets/Art Assets/Models/Tree1.prefab +++ b/Assets/Art Assets/Models/Tree1.prefab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bd1127969efc14c549a3aa08c973e71c51a33bec1a6c559bdf22547974add860 +oid sha256:1059c0979fed2cb164b7512ff93a07aca68c29feb6eca50eacbf89ab52b6dc6f size 14422 diff --git a/Assets/Prefab/PlayerController.prefab b/Assets/Prefab/PlayerController.prefab index dd5d86c..d41516d 100644 --- a/Assets/Prefab/PlayerController.prefab +++ b/Assets/Prefab/PlayerController.prefab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c84566b5ca89a9d052f943353c73777bbe5c5f0e95c9abf13cd20ffdd974ca18 -size 45794 +oid sha256:085084d72bb04099824ed788d05e72e012248b66dec77318c22644255679b5ac +size 46689 diff --git a/Assets/Prefab/Tile_01_obstacle.prefab b/Assets/Prefab/Tile_01_obstacle.prefab new file mode 100644 index 0000000..a266299 --- /dev/null +++ b/Assets/Prefab/Tile_01_obstacle.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a79a16b1c0d48fb1ef1a902e0e67d28789f18a16cf87c991682a8c9a60cf8f9f +size 6657 diff --git a/Assets/Prefab/Tile_01_obstacle.prefab.meta b/Assets/Prefab/Tile_01_obstacle.prefab.meta new file mode 100644 index 0000000..086a46d --- /dev/null +++ b/Assets/Prefab/Tile_01_obstacle.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5beeed0917dd204f8bfcad0337710e9 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefab/Tile_02_obstacle.prefab b/Assets/Prefab/Tile_02_obstacle.prefab new file mode 100644 index 0000000..d440f64 --- /dev/null +++ b/Assets/Prefab/Tile_02_obstacle.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c18b7ebf40ab3021e1efc5302ed00cb73345110b73cb2440081ac0af397c047e +size 14194 diff --git a/Assets/Prefab/Tile_02_obstacle.prefab.meta b/Assets/Prefab/Tile_02_obstacle.prefab.meta new file mode 100644 index 0000000..937c90a --- /dev/null +++ b/Assets/Prefab/Tile_02_obstacle.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 369339ac2f938b34e998dd187315aa48 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/BoatController.cs b/Assets/Scripts/BoatController.cs index 239158f..4f5994e 100644 --- a/Assets/Scripts/BoatController.cs +++ b/Assets/Scripts/BoatController.cs @@ -19,6 +19,10 @@ public class BoatController : MonoBehaviour [SerializeField] private bool m_usedebugkeys; + [SerializeField] + private AudioClip[] m_bonkClips; + + void Awake() { rigidBody = GetComponent(); @@ -103,7 +107,7 @@ public class BoatController : MonoBehaviour Debug.Log($"Hitting: {collision.gameObject} Foce: {collision.impulse * ObstacleBounce}"); rigidBody.AddForce(collision.impulse * ObstacleBounce, ForceMode.Impulse); - + SFXPlayer.Play(m_bonkClips); } diff --git a/Assets/Scripts/Player/BoatRowController.cs b/Assets/Scripts/Player/BoatRowController.cs index 6868a09..fc12580 100644 --- a/Assets/Scripts/Player/BoatRowController.cs +++ b/Assets/Scripts/Player/BoatRowController.cs @@ -16,6 +16,8 @@ public class BoatRowController : MonoBehaviour public UnityEvent m_OnRow; public UnityEvent m_OnBrake; public int velocityOverFrames = 8; + + public AudioClip[] m_rowClips; #endregion Inspector Fields #region Private Fields @@ -109,6 +111,7 @@ public class BoatRowController : MonoBehaviour else { //Debug.Log($"Row! ({averageVelocity})"); + SFXPlayer.Play(m_rowClips); m_OnRow.Invoke(averageVelocity); } } diff --git a/Assets/Scripts/SFXPlayer.cs b/Assets/Scripts/SFXPlayer.cs new file mode 100644 index 0000000..67373bb --- /dev/null +++ b/Assets/Scripts/SFXPlayer.cs @@ -0,0 +1,151 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using NaughtyAttributes; +using System.Linq; + +/// +/// +/// +public class SFXPlayer : MonoBehaviour +{ + + private static SFXPlayer instance; + + + #region Inspector Fields + + [SerializeField, MinMaxSlider(-1, 1)] + public Vector2 pitchRange = new Vector2(-0.1f, 0.1f); + + [SerializeField, MinMaxSlider(-1, 1)] + public Vector2 volumeRange = new Vector2(-0.1f, 0.1f); + + + #endregion Inspector Fields + + #region Private Fields + private List m_playingClips = new List(); + #endregion Private Fields + + #region Getters + + #endregion Getters + + + + #region MonoBehaviour Functions + /// + /// OnEnable is called when the object becomes enabled and active. + /// + private void OnEnable() + { + instance = this; + DontDestroyOnLoad(transform.root.gameObject); + } + + /// + /// OnDisable is called when the behaviour becomes disabled. + /// + private void OnDisable() + { + + } + + private void OnDestroy() + { + instance= null; + } + + /// + /// Update is called once per frame + /// + private void Update() + { + + } + + #endregion MonoBehaviour Functions + + #region Class Functionality + + public static void Play(params AudioClip[] clip) + { + CreateInstace(); + instance?.PlaySoundClip(clip); + } + + + public static bool isPlaying(params AudioClip[] clips) + { + + if (instance == null) + return false; + + foreach (AudioClip clip in clips) + if (instance.m_playingClips.Contains(clip)) + return true; + return false; + } + + private static void CreateInstace() + { + if (instance != null) + return; + + GameObject gameObject = new GameObject("SFX Player"); + gameObject.AddComponent(); + } + + + public void PlaySoundClip(params AudioClip[] clips) + { + + + if (clips.Length == 0 || isPlaying(clips)) + return; + + AudioClip selectedClip = clips[Random.Range(0, clips.Length)]; + + GameObject gameObject = new GameObject(selectedClip.name); + gameObject.transform.parent = transform; + + AudioSource source = gameObject.AddComponent(); + source.clip = selectedClip; + + source.volume = 0.8f + Random.Range(volumeRange.x, volumeRange.y); + source.pitch = 1 + Random.Range(pitchRange.y, pitchRange.x); + source.spatialBlend = 0; + + + m_playingClips.AddRange(clips); + source.Play(); + + + StartCoroutine(DestroyAfter(selectedClip.length,gameObject , clips)); + + + } + + private IEnumerator DestroyAfter(float t,GameObject gameObject, params AudioClip[] clips) + { + yield return new WaitForSeconds(t); + m_playingClips.RemoveAll(p => clips.Contains(p)); + Destroy(gameObject); + } + + + + #endregion Class Functionality + + #region Editor Functions + /// + /// Called when the Component is created or Reset from the Inspector + /// + private void Reset() + { + //useful for finding components on creation + } + #endregion Editor Functions + +} \ No newline at end of file diff --git a/Assets/Scripts/SFXPlayer.cs.meta b/Assets/Scripts/SFXPlayer.cs.meta new file mode 100644 index 0000000..c9ec82f --- /dev/null +++ b/Assets/Scripts/SFXPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0a1619328788c745a081292a258f7a6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: