【发布时间】:2019-01-13 02:36:30
【问题描述】:
我已经尝试添加此功能已经有一段时间了。不过,我好像忽略了什么。
所以我想添加一个弹药数量,一个类似于 Quake 或 Doom 的单个弹药数量。弹药拾取器分布在整个地图上。枪最多可以发射 10 次然后停止,但是当我尝试通过与弹药拾取器重叠来重新加载时,静态网格没有响应。静态 mash 父级是一个蓝图(actor),它的父类是 ammocrate.cpp(下图),它也是一个actor。这是我到目前为止所做的。
AmmoCrate.cpp
AAmmoCrate::AAmmoCrate()
{
PrimaryActorTick.bCanEverTick = true;
Count = 10;
SphereRadius = 100.0f;
TouchSphere = CreateDefaultSubobject<USphereComponent>(TEXT("TouchSphereComponent"));
TouchSphere->InitSphereRadius(SphereRadius);
TouchSphere->SetCollisionProfileName("Trigger");
RootComponent = TouchSphere;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
StaticMesh->SetupAttachment(RootComponent);
TouchSphere->OnComponentBeginOverlap.AddDynamic(this, &AAmmoCrate::OnOverlapBegin);
}
void AAmmoCrate::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
AFirstPersonCharacter *FPCharacter = Cast<AFirstPersonCharacter>(OtherActor);
AMannequin* TPCharacter = Cast<AMannequin>(OtherActor);
AGun *Gun = Cast<AGun>(OtherActor);
if (TPCharacter)
{
Gun->AmmoPool = Gun->AmmoPool + Count;
this->Destroy();
}
之后我创建了一个类似于 OnFire() 函数的 OnReload() 函数,我从第一人称角色中调用它。
FirstPersonCharacter.cpp
void AFirstPersonCharacter::OnReload()
{
Gun->OnReload();
}
我在 OnReload 函数上设置了 UE_LOG 调用,它甚至没有注销弹药箱已经重叠,我在这里缺少什么?
【问题讨论】:
-
你的重叠体积比你的网格大吗?
标签: c++ unreal-engine4 unreal-development-kit