向游戏添加弹药计数。

时间:2018-08-06 07:22:47

标签: c++ unreal-engine4 unreal-development-kit

我已经尝试添加此功能已有一段时间了。但是,似乎我正在忽略某些东西。

所以我想添加一个弹药数,一个类似于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调用,它甚至没有注销弹药箱已经重叠的信息,我在这里错过了什么?

1 个答案:

答案 0 :(得分:0)

在FPS角色胶囊和弹药箱对撞机的碰撞设置中,GenerateOverlapEvents是否检查为true? 这两个对撞机是否都在可以产生重叠事件的适当渠道中?

相关问题