unity3d - 以全音量播放3D声音

标签 unity3d audio

在我的第一人称射击游戏(团结)中,我使用AudioSource.PlayClipAtPoint指示敌人的生成。玩家必须听到3D声音,这一点很重要,这样他才能知道敌人在哪里生成。
这很好,但由于敌人距离很远,声音的音量很低。

有没有一种方法可以使团结忽略距离,但保持3D声音的容量,以便仍然可以分辨出敌人是否在它们后面/上方/ ...产生?

我现在通过将其他体积(例如,枪击)减少到0.05来处理此问题。当然,这确实使游戏整体安静。

任何帮助深表感谢!

最佳答案

我的建议是朝敌人生成的方向播放AudioSource.PlayClipAtPoint(),但不一定要在其位置播放。这样,您仍然可以为敌人产生的方向提供适当的听觉提示,但是您可以以恒定的音量播放它们。

基本方法是计算玩家与敌人生成的物体之间的单位 vector ,然后将此 vector 添加到玩家的位置以确定在何处播放生成声音。这是一个外观的想法(其中player是包含摄像机的GameObject):

// First, calculate the direction to the spawn
Vector3 spawnDirection = targets[i].transform.position - player.transform.position;

// Then, normalize it into a unit vector
Vector3 unitSpawnDirection = spawnDirection.normalized;

// Now, we can play the sound in the direction, but not position, of the spawn
AudioSource.PlayClipAtPoint(spawnSound, player.transform.position + unitSpawnDirection);

之后,您只需要将要播放的音频剪辑的音量更改为您想要的音量即可。希望这可以帮助!如果您有任何问题,请告诉我。

关于unity3d - 以全音量播放3D声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48428706/

相关文章:

algorithm - 检测音频样本中最大的动态范围变化

Unity3d 编辑器 : how to prevent changes from being undone upon exiting play mode?

file - 计算音频文件的校验和而不考虑标题

java - 如何保存并发送音频文件

c# - A*(A 星)算法不完全有效

c# - 将音频信号从内存流分别拆分为帧。字节数组 [C#]

c# - 如何从 URL 流式传输/下载和播放音频?

c# - 确保奖池不会奖励并列的参与者少于得分较差的参与者

c# - 如何统一使用.Net 4.6.1?

unity3d - unity Vuforia NullReferenceException