Joshua 1 year ago
parent
commit
88fcd12d1e
17 changed files with 216 additions and 7 deletions
  1. BIN
      Assets/Art Assets/Models/RockPile_obstacle.prefab
  2. +7
    -0
      Assets/Art Assets/Models/RockPile_obstacle.prefab.meta
  3. BIN
      Assets/Art Assets/Models/Tree1 1.prefab
  4. BIN
      Assets/Art Assets/Models/Tree1 2.prefab
  5. BIN
      Assets/Art Assets/Models/Tree1 3.prefab
  6. BIN
      Assets/Art Assets/Models/Tree1 4.prefab
  7. +7
    -0
      Assets/Art Assets/Models/Tree1 4.prefab.meta
  8. BIN
      Assets/Art Assets/Models/Tree1.prefab
  9. BIN
      Assets/Prefab/PlayerController.prefab
  10. BIN
      Assets/Prefab/Tile_01_obstacle.prefab
  11. +7
    -0
      Assets/Prefab/Tile_01_obstacle.prefab.meta
  12. BIN
      Assets/Prefab/Tile_02_obstacle.prefab
  13. +7
    -0
      Assets/Prefab/Tile_02_obstacle.prefab.meta
  14. +5
    -1
      Assets/Scripts/BoatController.cs
  15. +3
    -0
      Assets/Scripts/Player/BoatRowController.cs
  16. +151
    -0
      Assets/Scripts/SFXPlayer.cs
  17. +11
    -0
      Assets/Scripts/SFXPlayer.cs.meta

BIN
Assets/Art Assets/Models/RockPile_obstacle.prefab (Stored with Git LFS) View File

size 29993

+ 7
- 0
Assets/Art Assets/Models/RockPile_obstacle.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8c6aea957cd47ea44bac73fce15ca440
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Art Assets/Models/Tree1 1.prefab (Stored with Git LFS) View File

size 15008

BIN
Assets/Art Assets/Models/Tree1 2.prefab (Stored with Git LFS) View File

size 16139

BIN
Assets/Art Assets/Models/Tree1 3.prefab (Stored with Git LFS) View File

size 16728

BIN
Assets/Art Assets/Models/Tree1 4.prefab (Stored with Git LFS) View File

size 32240

+ 7
- 0
Assets/Art Assets/Models/Tree1 4.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 27e23f110c0eb104ab4d0ce45e81ac31
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Art Assets/Models/Tree1.prefab (Stored with Git LFS) View File

size 14422

BIN
Assets/Prefab/PlayerController.prefab (Stored with Git LFS) View File

size 46689

BIN
Assets/Prefab/Tile_01_obstacle.prefab (Stored with Git LFS) View File

size 6657

+ 7
- 0
Assets/Prefab/Tile_01_obstacle.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e5beeed0917dd204f8bfcad0337710e9
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Prefab/Tile_02_obstacle.prefab (Stored with Git LFS) View File

size 14194

+ 7
- 0
Assets/Prefab/Tile_02_obstacle.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 369339ac2f938b34e998dd187315aa48
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 5
- 1
Assets/Scripts/BoatController.cs View File

@ -19,6 +19,10 @@ public class BoatController : MonoBehaviour
[SerializeField]
private bool m_usedebugkeys;
[SerializeField]
private AudioClip[] m_bonkClips;
void Awake()
{
rigidBody = GetComponent<Rigidbody>();
@ -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);
}

+ 3
- 0
Assets/Scripts/Player/BoatRowController.cs View File

@ -16,6 +16,8 @@ public class BoatRowController : MonoBehaviour
public UnityEvent<float> 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);
}
}

+ 151
- 0
Assets/Scripts/SFXPlayer.cs View File

@ -0,0 +1,151 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
using System.Linq;
/// <summary>
///
/// </summary>
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<AudioClip> m_playingClips = new List<AudioClip>();
#endregion Private Fields
#region Getters
#endregion Getters
#region MonoBehaviour Functions
/// <summary>
/// OnEnable is called when the object becomes enabled and active.
/// </summary>
private void OnEnable()
{
instance = this;
DontDestroyOnLoad(transform.root.gameObject);
}
/// <summary>
/// OnDisable is called when the behaviour becomes disabled.
/// </summary>
private void OnDisable()
{
}
private void OnDestroy()
{
instance= null;
}
/// <summary>
/// Update is called once per frame
/// </summary>
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<SFXPlayer>();
}
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<AudioSource>();
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
/// <summary>
/// Called when the Component is created or Reset from the Inspector
/// </summary>
private void Reset()
{
//useful for finding components on creation
}
#endregion Editor Functions
}

+ 11
- 0
Assets/Scripts/SFXPlayer.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0a1619328788c745a081292a258f7a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save