I’m having issues with the sound aspect of my game. I want the sound to increase/decrease depending on the state of what my character is doing. For example, when I crouch, the footsteps sound decrease, while he’s sprinting the sound increases, etc. Also, I’m having an issue where the sound keeps looping after I’ve released the keys.
I’ve also originally added an else statement, where audio.volume = 0.0f, so that when no key’s are pressed no sound plays. But that caused the volumes to remain at 0.
using UnityEngine;
using System.Collections;
public class FootstepsSound : MonoBehaviour
{
// Use this for initialization
void Start ()
{
audio.volume = 0.0f;
}
// Update is called once per frame
void Update ()
{
//audio.volume ranges from 0 to 1
WalkingSound();
CrouchingSound();
SprintingSound();
}
void WalkingSound()
{
if(Input.GetButtonDown(“Horizontal”) || Input.GetButtonDown(“Vertical”))
{
audio.volume = 0.6f;
audio.Play();
}
}
void CrouchingSound()
{
if(Input.GetButtonDown(“Horizontal”) || Input.GetButtonDown(“Vertical”))
{
if(Input.GetKey(KeyCode.LeftControl))
{
audio.volume = 0.3f;
audio.Play();
}
}
}
void SprintingSound()
{
if(Input.GetButtonDown(“Horizontal”) || Input.GetButtonDown(“Vertical”))
{
if(Input.GetKey(KeyCode.LeftShift))
{
audio.volume = 1.0f;
audio.Play();
}
}
}
}