Advertisement
Guest User

Untitled

a guest
Jan 24th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include "WaterAnimation.h"
  2. #include <cmath>
  3.  
  4. // Sets default values
  5. AWaterAnimation::AWaterAnimation()
  6. {
  7.     UE_LOG(LogTemp, Warning, TEXT("Constructor"));
  8.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  9.     PrimaryActorTick.bCanEverTick = true;
  10.  
  11.     ConstructorHelpers::FObjectFinder<UStaticMesh> ModelPath1(TEXT("StaticMesh'/Game/Objects/Dam/Water/Mesh/fluid_animation_open_000580.fluid_animation_open_000580'"));
  12.     frame1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("waterFrame1"));
  13.     frame1->SetStaticMesh(ModelPath1.Object);
  14.     frame1->SetCollisionEnabled(ECollisionEnabled::NoCollision);
  15.     frame1->AttachTo(RootComponent);
  16.  
  17.     ConstructorHelpers::FObjectFinder<UStaticMesh> ModelPath2(TEXT("StaticMesh'/Game/Objects/Dam/Water/Mesh/fluid_animation_open_000500.fluid_animation_open_000500'"));
  18.     frame2 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("waterFrame2"));
  19.     frame2->SetStaticMesh(ModelPath2.Object);
  20.     frame2->SetCollisionEnabled(ECollisionEnabled::NoCollision);
  21.     frame2->AttachTo(RootComponent);
  22. }
  23.  
  24. // Called when the game starts or when spawned
  25. void AWaterAnimation::BeginPlay()
  26. {
  27.     UE_LOG(LogTemp, Warning, TEXT("Begin Play"));
  28.     Super::BeginPlay();
  29.    
  30. }
  31.  
  32. // Called every frame
  33. void AWaterAnimation::Tick(float DeltaTime)
  34. {
  35.     UE_LOG(LogTemp, Warning, TEXT("Tick"));
  36.     Super::Tick(DeltaTime);
  37.  
  38.     currentTime += DeltaTime;
  39.     float elapsedTime = currentTime - startingTime;
  40.  
  41.     if ((((int)floor(elapsedTime)) % 2) == 0) {
  42.         frame2->SetVisibility(true);
  43.         frame1->SetVisibility(false);
  44.     }
  45.     else {
  46.         frame1->SetVisibility(true);
  47.         frame2->SetVisibility(false);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement