Skip to content

Commit

Permalink
added splash and land sound
Browse files Browse the repository at this point in the history
  • Loading branch information
joesobo committed Dec 5, 2020
1 parent 3762d08 commit 8f10796
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Binary file added Assets/Audio/land.wav
Binary file not shown.
Binary file added Assets/Audio/splash.wav
Binary file not shown.
4 changes: 3 additions & 1 deletion Assets/Scenes/Level1.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1102036,7 +1102036,7 @@ MonoBehaviour:
useMoons: 0
useBirds: 0
useAtmosphere: 0
useWater: 0
useWater: 1
daylightCycle: 0
useCrates: 0
useEnvironmentObjects: 0
Expand Down Expand Up @@ -2419141,6 +2419141,8 @@ MonoBehaviour:
shootMainAudioClip: {fileID: 8300000, guid: 810baedc4abdef34c885b8d5a8bf1055, type: 3}
shootAltAudioClip: {fileID: 8300000, guid: dab0de869dacbb347bd74ac05e5e10df, type: 3}
powerupClip: {fileID: 8300000, guid: 1ef303839eca7c24b9b119adf3c13e05, type: 3}
landClip: {fileID: 8300000, guid: 53e77247f7fa17840a9316964879c9d0, type: 3}
splashClip: {fileID: 8300000, guid: 57c38aa797b5d894681ed546c148c55f, type: 3}
--- !u!82 &650113250168139131
AudioSource:
m_ObjectHideFlags: 0
Expand Down
31 changes: 27 additions & 4 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlayerController : MonoBehaviour {
Expand All @@ -16,6 +17,7 @@ public class PlayerController : MonoBehaviour {
private Vector3 smoothMoveVelocity;
private Rigidbody rb;
private bool grounded;
private bool groundLocked = false;
private bool landParticleSpawned = false;

private GameSettings settings;
Expand Down Expand Up @@ -96,11 +98,18 @@ private void GroundCheck() {
if (Physics.Raycast(ray, out hit, .85f, groundMask)) {
hitGround = true;

if (!ps && settings.useParticle && !landParticleSpawned) {
ps = Instantiate(landParticles, transform.position, transform.rotation);
settings.SetParticleValues(ps);
landParticleSpawned = true;
if (!groundLocked) {
groundLocked = true;
soundManager.Play(PlayerSoundManager.Clip.land);

if (!ps && settings.useParticle && !landParticleSpawned) {
ps = Instantiate(landParticles, transform.position, transform.rotation);
settings.SetParticleValues(ps);
landParticleSpawned = true;
StartCoroutine("ResetParticle");
}
}

}
}

Expand Down Expand Up @@ -156,17 +165,31 @@ private void FixedUpdate() {

if (doJump) {
doJump = false;
StartCoroutine("ResetGroundLock");

rb.AddForce(transform.up * jumpForce);
soundManager.Play(PlayerSoundManager.Clip.jump);
}
}

void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Water") {
soundManager.Play(PlayerSoundManager.Clip.splash);

if (settings.useParticle) {
ps = Instantiate(waterParticles, transform.position, transform.rotation);
settings.SetParticleValues(ps);
}
}
}

IEnumerator ResetParticle() {
yield return new WaitForSeconds(0.1f);
ps = null;
}

IEnumerator ResetGroundLock() {
yield return new WaitForSeconds(0.1f);
groundLocked = false;
}
}
10 changes: 9 additions & 1 deletion Assets/Scripts/Player/PlayerSoundManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using UnityEngine;

public class PlayerSoundManager : MonoBehaviour {
public enum Clip { jump, shootMain, shootAlt, powerup };
public enum Clip { jump, shootMain, shootAlt, powerup, land, splash };

public AudioClip jumpAudioClip;
public AudioClip shootMainAudioClip;
public AudioClip shootAltAudioClip;
public AudioClip powerupClip;
public AudioClip landClip;
public AudioClip splashClip;

private AudioSource source;
private GameSettings settings;
Expand Down Expand Up @@ -37,6 +39,12 @@ public void Play(Clip audioClip) {
case Clip.powerup:
source.PlayOneShot(powerupClip);
break;
case Clip.land:
source.PlayOneShot(landClip);
break;
case Clip.splash:
source.PlayOneShot(splashClip);
break;
default:
break;
}
Expand Down

0 comments on commit 8f10796

Please sign in to comment.