关于特效的常用代码:
1.增加特效函数:
UGameplayStatics::SpawnEmitterAtLocation()
2.一个指向世界或者关卡的指针:
UWorld* (GetWorld()函数可以得到,Actor类里面定义的)
3.一个指向粒子组件的指针:
UParticleSystem*
4.一个位置的引用:
const FTransform & SpawnFTransform (this->GetTransform() 可以得到)
=======================================
上几期教程比较老,我们直接换个新一点的
1.我们找到子弹的头文件AFPSGameProjectile.h
2.添加一个粒子组件,protected类型,并只能在蓝图中赋值
- protected:
- UPROPERTY(EditDefaultsOnly, Category = "Emitter")
- UParticleSystem * Emitter_Projectile;
3.找到负责执行碰撞的函数
- /** called when projectile hits something */
- UFUNCTION()
- void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
4.在其对应的源文件里导入UGameplayStatics静态类的头文件
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
5.在对应源文件里找到其定义碰撞的函数,然后添加特效
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), Emitter_Projectile, this->GetTransform());
6.编译
=============================
进入虚幻编辑器
1.找到子弹蓝图
2.发现可以赋值特效了,不过category已经被翻译了
3.选择爆炸特效
4.测试 成功