Unity3D 게임의 버튼에 버튼 클릭 사운드를 추가하려고했습니다. 그러나, 내가 시도한 모든 것 (아래 참조)은 원하는 효과 (클릭시 소리)를 생성하지 않습니다. 버튼은 작동하지만 소리가 나지 않습니다. 다음 링크에는 제가 시도한 것들이 포함되어 있으며, 스크립팅에 대한 최신 시도도 첨부되어 있습니다. 오디오는 (마지막 링크 당) 검사관으로부터 재생되도록 설정되어 있기 때문에 스크립트 자체에는 audioSource.play()
이 없습니다. 나는 버튼을 클릭 할 때 소리를 재생하려면 :버튼 클릭 사운드 추가 Unity3D 5.4
http://answers.unity3d.com/questions/26241/play-sound-when-gui-button-is-pressed.html http://answers.unity3d.com/questions/182754/play-sound-on-button-press.html http://answers.unity3d.com/questions/857810/play-audio-from-46-ui-button-on-click-script.html
private AudioSource audioSource;
private float audioTimer;
public void LoadLevel(string name)
{
StartCoroutine(AudioLength(audioTimer));
SceneManager.LoadScene(name);
}
public void Next(string name)
{
StartCoroutine(AudioLength(audioTimer));
SceneManager.LoadScene(name);
}
void Start()
{
audioSource = this.GetComponent<AudioSource>();
audioTimer = audioSource.clip.length;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene("Start Menu");
}
else if(Input.GetKeyDown(KeyCode.Q))
{
Application.Quit();
}
}
IEnumerator AudioLength(float audioTimer)
{
yield return new WaitForSeconds(audioTimer);
}