1 创建Actor/AuraEffectActor类,删掉Tick函数

2 在AuraEffectActor.h中

创建TObject<USphereComponent> Sphere;

重写virtual void OnOverlap(UPrimitiveCompinent* Overlap...);

重写virtual void EndOverlap(UPrimitiveCompinent* Overlap...);

TObject<UStaticMeshComponent> Mesh

3 在AuraEffectActor.cpp中

给上面的初始化:

构造中:

PrimaryActorTick.bCanEverTick = false;

Sphere = CreateDefaultSubobject<USphereComponent>("Sphere");

Mesh= CreateDefaultSubobject<UStaticMeshComponent>("Mesh");

SetRootComponent(Mesh);

Sphere ->SetupAttachment(GetRootComponent());

 

BeginPlay()

{

  Sphere->OnComponentBeginOverlap.AddDynamic(this,&AAuraEffectActor::OnOverlap);

Sphere->OnComponentEndOverlap.AddDynamic(this,&AAuraEffectActor::EndOverlap);

}

 

OnOverlap()

{

  if(IAbilitySystemInterface* ASCInterface = Cast<IAbilitySystemInterface>(OtherActor))

  {

//TODO: Change this to apply a Gameplay Effect. FOr now using const_cast as a back!

    cosnt UAuraAttributeSet* AuraAttributeSet = ASCInterface->GetAbilitySystemComponent()->GetAttributeSet(UAuraAttributeSet::StaticClass());

    UAuraAttributeSet* MutableAuraAttributeSet = const_cast<UAuraAttributeSet*>(AuraAttributeSet);

    MutableAuraAttributeSet ->SetHealth(AuraAttributeSet->GetHealth() + 25.f);

    Destory();

}

}

4 在内容浏览器中创建Actor文件夹、BP_HealthPotion

在蓝图中,添加相应的静态网格体

 

posted on 2025-08-14 23:15  偷懒的阿贤  阅读(6)  评论(0)    收藏  举报