var sound : AudioClip;
function Update (){
if(Input.GetButtonDown(“Vertical”)){
audio.PlayOneShot(sound);
}
}
While pressing the play sound only once. What should I add the code for that sound plays over and over again if I hold the key?
var sound : AudioClip;
function Update (){
if(Input.GetButtonDown(“Vertical”)){
audio.PlayOneShot(sound);
}
}
While pressing the play sound only once. What should I add the code for that sound plays over and over again if I hold the key?
using UnityEngine;
using System.Collections;
public class playSound : MonoBehaviour {
public AudioSource mySound;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Mouse0))
{
mySound.enabled = true;
mySound.loop = true;
}
else
{
mySound.enabled = false;
mySound.loop = false;
}
}
}
Just audio.Play(sound) isn’t it?
I checked the docs and there is a bit about audio.Play().
Have a look at this.