user-interface - 每次按下带有 Button 组件的 GameObject 时,如何播放声音?
问题描述
我试过用这个,但声音不播放。
public class audioManager : MonoBehaviour {
public EventSystem EventSystemManager;
public AudioClip buttonSound;
AudioSource audioSource;
GameObject game_object;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
game_object = EventSystemManager.currentSelectedGameObject;
if (game_object.GetComponent<Button>())
PlaySound(buttonSound);
}
}
void PlaySound(AudioClip sound)
{
audioSource = game_object.AddComponent<AudioSource>();
audioSource.clip = sound;
audioSource.Play();
Destroy(audioSource);
}
我怎样才能得到这个工作?我尝试了其他一些技术,但仍然没有结果。
解决方案
推荐阅读
- twilio - 将呼叫从 Twilio 自动驾驶转移到 Taskrouter?
- c - 如何找到 7x+2y=n 的所有正整数解
- regex - 从非唯一表行中提取单词 Tableau 2020.2.6
- python - 在c文件中编译python时的问题
- angular - Angular:拖放垫预览未显示
- javascript - Javascript/Jquery 返回明天的日期,但跳过周日
- qt - 如何在 Qt 小部件中获取屏幕更改事件
- vba - EOF VBA 阻止我访问文件的最后一行
- javascript - Mongoose 查询以获取特定日期的数据 (MongoDB)
- selenium - 将 selenium 请求存储在 jmeter 中以在下一个请求中使用