Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //teletrasportatore.h
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "CoreMinimal.h"
- #include "Components/ActorComponent.h"
- #include "Teletrasportatore.generated.h"
- UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
- class FPS_TEST_API UTeletrasportatore : public UActorComponent
- {
- GENERATED_BODY()
- public:
- // Sets default values for this component's properties
- UTeletrasportatore();
- protected:
- // Called when the game starts
- virtual void BeginPlay() override;
- UInputComponent* InputComponent;
- public:
- // Called every frame
- virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
- UFUNCTION(BlueprintCallable, Category = "Movement")
- void TentaTeletrasporto(float DeltaTime, bool forzato = false);
- private:
- AActor* owner = nullptr;
- float TempoTrascorso = 0.0;
- UPROPERTY(EditAnywhere)
- bool AutoTele = false;
- };
- //==================================================================================
- //==================================================================================
- //==================================================================================
- //teletrasportatore.cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "Teletrasportatore.h"
- // Sets default values for this component's properties
- UTeletrasportatore::UTeletrasportatore()
- {
- // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
- // off to improve performance if you don't need them.
- PrimaryComponentTick.bCanEverTick = true;
- // ...
- }
- // Called when the game starts
- void UTeletrasportatore::BeginPlay()
- {
- Super::BeginPlay();
- owner = GetOwner();
- // ...
- }
- // Called every frame
- void UTeletrasportatore::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
- {
- Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
- if (!AutoTele) return;
- TentaTeletrasporto(DeltaTime);
- }
- void UTeletrasportatore::TentaTeletrasporto(float DeltaTime, bool forzato)
- {
- TempoTrascorso += DeltaTime;
- if (TempoTrascorso >= 5 || forzato)
- {
- if (FMath::FRand() > 0.99 || forzato)
- {
- TempoTrascorso = 0;
- owner->SetActorLocation(FVector(1500, 1500, 0) + FVector(
- FMath::RandRange(0, 100),
- FMath::RandRange(0, 100),
- 400));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement