1. 程式人生 > >UE C++程式碼新增球形碰撞體

UE C++程式碼新增球形碰撞體

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SphereComponent.h"
#include "Collecable.generated.h"


UCLASS()
class PACMAN_API ACollecable : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ACollecable();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;


	UPROPERTY(EditDefaultsOnly,Category=Collect)
	USphereComponent* BaseCollisionComponent;
	
};





// Fill out your copyright notice in the Description page of Project Settings.

#include "Collecable.h"
#include "Public/UObject/ConstructorHelpers.h"

// Sets default values
ACollecable::ACollecable()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;

	BaseCollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("BaseCollisionConponent"));
	BaseCollisionComponent->SetSphereRadius(16);
	//static ConstructorHelpers::FObjectFinder<UStaticMesh> Sphere(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));

}

// Called when the game starts or when spawned
void ACollecable::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ACollecable::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}