Hello all. Not much of a coder but I’m trying to have a short audio clip play whenever the player presses spacebar.
Right now the player is able to jump by pressing spacebar and if they hold it down they continue to rise for about three seconds before they begin falling. I would like the audioclip to play for as long as they are rising, but currently it plays the entire audio file (about 27 seconds long). I understand that my current code doesn’t tell it to stop, but I’m having a hard time figuring out how to play the audio, wait for three seconds, then stop and reset the audio.
my spacethrusters script (C#) is attached to my fps controller along with the audiosource component.
Any help at all would be great, here’s the current code I have:
using UnityEngine;
using System.Collections;
public class spacethrusters : MonoBehaviour {
//Update is called once per frame
void Update () {
if (Input.GetKeyDown("space"))
audio.Play ();
}
}
Thanks again.