// Invadersprojcetile.h #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "InvadersProjectile.generated.h" class UCapsuleComponent; class UStaticMeshComponent; class UProjectileMovementComponent; UCLASS() class INVADERS_API AInvadersProjectile : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AInvadersProjectile(); protected: UPROPERTY(EditDefaultsOnly) TObjectPtr ProjectileCollision; UPROPERTY(EditDefaultsOnly) TObjectPtr ProjectileMesh; UPROPERTY(EditDefaultsOnly) TObjectPtr ProjectileMovement; };
@Narazves_gamedev11 ай бұрын
// InvadersProjectile.cpp #include "InvadersProjectile.h" #include "Components/CapsuleComponent.h" #include "Components/StaticMeshComponent.h" #include "GameFramework/ProjectileMovementComponent.h" // Sets default values AInvadersProjectile::AInvadersProjectile() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; ProjectileCollision = CreateDefaultSubobject(TEXT("ProjectileCollision")); ProjectileMesh = CreateDefaultSubobject(TEXT("ProjectileMesh")); ProjectileMovement = CreateDefaultSubobject(TEXT("ProjectileMovement")); check(ProjectileCollision); check(ProjectileMesh); check(ProjectileMovement); SetRootComponent(ProjectileCollision); ProjectileMesh->SetupAttachment(ProjectileCollision); ProjectileCollision->SetCapsuleHalfHeight(30.0); ProjectileCollision->SetCapsuleRadius(20.0); ProjectileMesh->SetRelativeScale3D(FVector(0.4, 0.4, 0.6)); SetLifeSpan(4.0); }