gpt4 book ai didi

audio - Unity无法将声音输入检查器字段

转载 作者:行者123 更新时间:2023-12-03 01:57:42 24 4
gpt4 key购买 nike

我有声音来源,我的问题是当我的立方体撞到墙上时如何播放声音?
我的代码:

usingUnityEngine;
usingSystem.Collections;

public class sound : MonoBehaviour {

public AudioSource soundEffect;

voidOnTriggerEnter (Collider other)
{
if(other.gameObject.tag == "wall")
{
soundEffect.Play ();
}
}
}

我无法在检查器中将音频源分配给脚本。我无法将 *.mp3文件放入字段。

该怎么办?

谢谢

最佳答案

如果您将音频源添加到多维数据集并将文件放置在“资源”中,则只要您想播放音频,就可以执行此操作

GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("audioFile");
GetComponent<AudioSource> ().Play ();

这是在C#中

关于audio - Unity无法将声音输入检查器字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34143749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com