我有一个声音提示,每当玩家做一个特定的动作时,我都想要播放它。我已经让它运行得很好了,但我想让使用的资源来自配置文件,而不是硬编码。
因此,我向我的类添加了一个名为MonsterNoiseSoundCue的属性,如下所示:
var config SoundCue MonsterNoiseSoundCue;然后,在DefaultProperties部分,我将以下代码添加到我创建的对象中,然后将其添加到我的兵的components集合中。
Begin Object Class=AudioComponent Name=MonsterActivatedSound1
bAutoPlay=false
SoundCue=MonsterNoiseSoundCue// This variable is a configured value. SoundCue'CastleAudio.UI.UI_StopTouchToMove_Cue'
End Object
Components.Add(MonsterActivatedSound1);
MonsterActivatedSound = MonsterActivatedSound1;由于某种原因,它不会在构建时声明“不允许对对象变量使用'config‘”。有谁知道另一种方法来解决这个问题?
发布于 2011-02-04 13:54:39
“不允许对对象变量使用'config‘。”消息是UnrealEngine 3中的一个变化。
我现在不能测试,我是一个UT2004脚本编写者,但我会尝试这样做:
var SoundCue MonsterNoiseSoundCue;
var config string MonsterNoiseSoundCueName;在您的PreBeginPlay函数(或类似函数)中,使用以下命令来获取提示:
MonsterNoiseSoundCue = SoundCue(DynamicLoadObject(MonsterNoiseSoundCueName, class'SoundCue'));如果声音提示不存在,您应该会在日志中收到警告。
发布于 2011-04-05 13:17:34
你用什么函数来播放声音?
PlaySound会动态创建一个AudioComponent,所以你不需要在defaultproperties部分有一个组件。
var config SoundCue MonsterNoiseSoundCue;然后,当您的操作发生时:
function OnMonsterAction()
{
PlaySound(MonsterNoiseSoundCue);
}发布于 2015-01-31 09:56:09
潜在的选项是动态组件的动态创建的组件
要动态创建组件的实例,请使用新操作符UnrealScript并调用执行元的AttachComponent方法将新组件附加到执行元。
simulated event PostBeginPlay()
{
local AudioComponent AudioComponent;
Super.PostBeginPlay();
AudioComponent = new(self) class'AudioComponent';
AudioComponent.SoundCue = Cue;//var(audio) SoundCue Cue
AudioComponent.bAutoPlay=true; // !!!
AttachComponent(AudioComponent); // Attach copm. to actor's copm. array
// .....
}要分离并释放先前附加的组件,请使用执行元的DetachComponent方法。
http://wiki.beyondunreal.com/UE3:AudioComponent_(UDK)
https://stackoverflow.com/questions/4894960
复制相似问题