You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

146 lines
3.0 KiB

using UnityEngine;
using System.Collections;
public class PlayerSounds : MonoBehaviour {
public GameObject PlayerObject; //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> ();
}
// 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(ControllerColliderHit FootHit){
//playerCollider = PlayerObject.GetComponent<CapsuleCollider>;
if (FootHit.gameObject.tag == "sand") {
FootOnSand = true;
}
else {
FootOnSand = false;
}
}
void PlayFootstep(){
float volRandom = Random.Range (volLowRange, volHighRange);
// 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);
}
}