using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class PlayerSounds : MonoBehaviour {
|
|
|
|
public GameObject PlayerObject;
|
|
private thirdPersonController playerController;//Player1 or Player2 object. Assign object component in inspector.
|
|
//private Collider playerCollider;
|
|
private bool FootOnSand = true;
|
|
|
|
private AudioSource source;
|
|
private float volLowRange = 0.5f; // Volume Low Range
|
|
private float volHighRange = 1.0f; // Volume High Range
|
|
private float pitchLowRange = 0.90f; // Pitch Low Range
|
|
private float pitchHighRange = 1.5f; // Pitch High Range
|
|
private float pitchDefault = 1.0f; // Pitch Default Value
|
|
|
|
|
|
// AUDIO CLIPS
|
|
// All player sound effects are listed here.
|
|
public AudioClip sfxFootSand;
|
|
public AudioClip sfxFootFloor;
|
|
public AudioClip sfxTEST;
|
|
public AudioClip sfxSwitch;
|
|
public AudioClip sfxPickUp;
|
|
public AudioClip sfxRotateL;
|
|
public AudioClip sfxRotateR;
|
|
public AudioClip sfxJump;
|
|
public AudioClip sfxLand;
|
|
|
|
// FUNCTION: Find Audio Source component (attached to **Player Avatar** Object)
|
|
void Awake(){
|
|
source = GetComponent<AudioSource> ();
|
|
}
|
|
|
|
void Start(){
|
|
playerController = PlayerObject.GetComponent<thirdPersonController> ();
|
|
}
|
|
|
|
|
|
// FUNCTIONS: Play Sound Effects (SFX)
|
|
// NOTE: Must add the events to the relevant keyframe within animation clips.
|
|
|
|
|
|
void Update () {
|
|
//CheckGround ();
|
|
}
|
|
|
|
|
|
|
|
// GROUND-TYPE RECOGNITION
|
|
// > Needs proper logic
|
|
// > Purpose of this function is to determine whether the player object is
|
|
// standing on the terrain object that has been tagged with "sand".
|
|
void CheckGround(){
|
|
|
|
//playerCollider = PlayerObject.GetComponent<CapsuleCollider>;
|
|
Debug.Log ("groundCheck");
|
|
|
|
FootOnSand = false;
|
|
|
|
RaycastHit FootHit = playerController.hit;
|
|
if (FootHit.collider != null) {
|
|
if (FootHit.transform.tag == "sand")
|
|
FootOnSand = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayFootstep(){
|
|
float volRandom = Random.Range (volLowRange, volHighRange);
|
|
|
|
CheckGround ();
|
|
|
|
|
|
// SAND FOOTSTEP SOUND
|
|
if(FootOnSand == true){
|
|
// SAND GROUND
|
|
source.pitch = Random.Range (pitchLowRange, pitchHighRange);
|
|
source.PlayOneShot (sfxFootSand,volRandom);
|
|
}
|
|
|
|
// GENERAL FOOTSTEP SOUND
|
|
else if (FootOnSand == false){
|
|
source.pitch = Random.Range (pitchLowRange, pitchHighRange);
|
|
source.PlayOneShot (sfxFootFloor,volRandom);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void PlayTest(){
|
|
float volRandom = Random.Range (volLowRange, volHighRange);
|
|
|
|
source.pitch = Random.Range (pitchLowRange, pitchHighRange);
|
|
source.PlayOneShot (sfxTEST,volRandom);
|
|
}
|
|
|
|
|
|
|
|
void PlayJump(){
|
|
float volRandom = Random.Range (volLowRange, volHighRange);
|
|
source.PlayOneShot (sfxJump,volRandom);
|
|
}
|
|
|
|
|
|
void PlayLand(){
|
|
float volRandom = Random.Range (volLowRange, volHighRange);
|
|
source.PlayOneShot (sfxLand,volRandom);
|
|
}
|
|
|
|
|
|
|
|
|
|
//CROSS-SCRIPT SOUNDS
|
|
// Sound functions assigned in different scripts, specifically those that
|
|
// require controller button presses.
|
|
|
|
|
|
public void PlaySwitch(){
|
|
source.pitch = pitchDefault;
|
|
source.PlayOneShot (sfxSwitch,0.7f);
|
|
}
|
|
|
|
|
|
|
|
public void PlayPickUp(){
|
|
source.pitch = pitchDefault;
|
|
source.PlayOneShot (sfxPickUp,0.7f);
|
|
}
|
|
|
|
|
|
public void PlayRotateL(){
|
|
source.pitch = pitchDefault;
|
|
source.PlayOneShot (sfxRotateL);
|
|
}
|
|
|
|
|
|
public void PlayRotateR(){
|
|
source.pitch = pitchDefault;
|
|
source.PlayOneShot (sfxRotateR);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|