2016-10-25 2 views
0

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); 
} 

답변

0

내가 community.gamedev.tv 두 사람의 도움을 통해 함께 해답을 발견했습니다.

먼저 오디오가 재생 될 수 있기 전에 장면이 변경되어 문제가 발생했습니다. 둘째로 지연을 처리하고 다음 장면을로드하려면 내 Coroutine에 LoadScene을 추가해야했습니다. 또한 내 코 루틴을 통해 문자열을 name 변수로 전달해야했습니다.

관련 문제