Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "GameFramework/Actor.h"
- #include "TutorialProject.h"
- #include "InteractableActor.generated.h"
- UCLASS()
- class TUTORIALPROJECT_API AInteractableActor : public AActor
- {
- GENERATED_BODY()
- public:
- // Sets default values for this actor's properties
- AInteractableActor();
- UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Interaction);
- void OnInteract(AActor* Caller);
- virtual void OnInteract_Implementation(AActor* Caller);
- void OnBeginFocus();
- void OnEndFocus();
- protected:
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- public:
- // Called every frame
- virtual void Tick(float DeltaTime) override;
- private:
- uint32 bCanInteract : 1;
- TArray<class UMeshComponent*> Meshes;
- EStencilColor Color = EStencilColor::SC_Blue;
- };
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "TutorialProject.h"
- #include "InteractableActor.h"
- #include "Avatar.h"
- // Sets default values
- AInteractableActor::AInteractableActor()
- {
- // 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;
- }
- // Called when the game starts or when spawned
- void AInteractableActor::BeginPlay()
- {
- Super::BeginPlay();
- for (UActorComponent* Mesh: GetComponentsByClass(UMeshComponent::StaticClass()))
- {
- UMeshComponent* thisMesh = Cast<UMeshComponent>(Mesh);
- if (thisMesh)
- {
- Meshes.Push(thisMesh);
- }
- }
- }
- // Called every frame
- void AInteractableActor::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- void AInteractableActor::OnInteract_Implementation(AActor* Caller) {
- AAvatar* Player = Cast<AAvatar>(Caller);
- if (Player)
- {
- UE_LOG(LogTemp, Warning, TEXT("Now Interacting"));
- Destroy();
- }
- }
- void AInteractableActor::OnBeginFocus()
- {
- if (bCanInteract)
- {
- for (UMeshComponent* Mesh : Meshes)
- {
- Mesh->SetRenderCustomDepth(true);
- Mesh->SetCustomDepthStencilValue((uint8)Color);
- }
- }
- }
- void AInteractableActor::OnEndFocus()
- {
- for (UMeshComponent* Mesh : Meshes)
- {
- Mesh->SetRenderCustomDepth(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement