Advertisement
fcamuso

Unreal Engine - video 12

Aug 27th, 2023
1,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. //teletrasportatore.h
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5. #pragma once
  6.  
  7. #include "CoreMinimal.h"
  8. #include "Components/ActorComponent.h"
  9. #include "Teletrasportatore.generated.h"
  10.  
  11.  
  12. UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
  13. class FPS_TEST_API UTeletrasportatore : public UActorComponent
  14. {
  15.     GENERATED_BODY()
  16.  
  17. public:
  18.     // Sets default values for this component's properties
  19.     UTeletrasportatore();
  20.  
  21. protected:
  22.     // Called when the game starts
  23.     virtual void BeginPlay() override;
  24.  
  25.     UInputComponent* InputComponent;
  26.    
  27.  
  28.     public:
  29.     // Called every frame
  30.     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
  31.    
  32.     UFUNCTION(BlueprintCallable, Category = "Movement")
  33.      void TentaTeletrasporto(float DeltaTime, bool forzato = false);
  34.  
  35. private:
  36.     AActor* owner = nullptr;
  37.     float TempoTrascorso = 0.0;
  38.  
  39.     UPROPERTY(EditAnywhere)
  40.         bool AutoTele = false;
  41.        
  42. };
  43. //==================================================================================
  44. //==================================================================================
  45. //==================================================================================
  46.  
  47.  
  48. //teletrasportatore.cpp
  49. // Fill out your copyright notice in the Description page of Project Settings.
  50.  
  51.  
  52. #include "Teletrasportatore.h"
  53.  
  54. // Sets default values for this component's properties
  55. UTeletrasportatore::UTeletrasportatore()
  56. {
  57.     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
  58.     // off to improve performance if you don't need them.
  59.     PrimaryComponentTick.bCanEverTick = true;
  60.    
  61.     // ...
  62. }
  63.  
  64.  
  65. // Called when the game starts
  66. void UTeletrasportatore::BeginPlay()
  67. {
  68.     Super::BeginPlay();
  69.     owner = GetOwner();
  70.  
  71.  
  72.     // ...
  73.    
  74. }
  75.  
  76.  
  77. // Called every frame
  78. void UTeletrasportatore::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
  79. {
  80.     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  81.  
  82.     if (!AutoTele) return;
  83.  
  84.     TentaTeletrasporto(DeltaTime);
  85. }
  86.  
  87. void UTeletrasportatore::TentaTeletrasporto(float DeltaTime, bool forzato)
  88. {
  89.     TempoTrascorso += DeltaTime;
  90.  
  91.     if (TempoTrascorso >= 5 || forzato)
  92.     {
  93.  
  94.         if (FMath::FRand() > 0.99 || forzato)
  95.         {
  96.             TempoTrascorso = 0;
  97.  
  98.             owner->SetActorLocation(FVector(1500, 1500, 0) + FVector(
  99.                 FMath::RandRange(0, 100),
  100.                 FMath::RandRange(0, 100),
  101.                 400));
  102.         }
  103.     }
  104. }
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement