Hello there!
The topic isnt really clear I know, its just I do not know how to ask it,
Now let me say this first, I consider myself to be very good in c++ and I have made very big programs in c++ and other languages, I have been making 2d games using allegro library, and it is different than unreal engine, and I guess that is because in allegro I can use my native C syntax, but I could not do it in Unreal engine
now, I have a class called countdown, this class will count from 3 to 0 and then wil be destroyed, my health class is just simple class that contains some functions/methods to reduce health && return health value, what I was thinking is I want to start reducing health after the countdown hits 0; and I want to know how do I implement that both in blue print and in C++ files,
//countdown
// Fill out your copyright notice in the Description page of Project Settings.
#include "QuickStart.h"
#include "Countdown.h"
// Sets default values
ACountdown::ACountdown()
{
// 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;
CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
CountdownText->SetHorizontalAlignment(EHTA_Center);
CountdownText->SetWorldSize(150.0f);
RootComponent = CountdownText;
CountdownTime = 3;
}
// Called when the game starts or when spawned
void ACountdown::BeginPlay()
{
Super::BeginPlay();
UpdateTimerDisplay();
GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvancedTimer, 1.0f, true);
}
// Called every frame
void ACountdown::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void ACountdown::UpdateTimerDisplay()
{
if (CountdownTime >= 1)
{
CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
UE_LOG(LogTemp, Warning, TEXT("Countdown for go %d"), CountdownTime);
}
}
void ACountdown::AdvancedTimer()
{
--CountdownTime;
UpdateTimerDisplay();
if (CountdownTime == 0)
{
CountdownHasFinished();
}
if (CountdownTime < -1)// destroy "GO" text after one second of showing
{
CountdownText->DestroyComponent(true);
//UE_LOG(LogTemp, Warning, TEXT("Destoying that thing"));
//UE_LOG(LogTemp, Warning, TEXT("health %d"), health);
GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
}
}
void ACountdown::CountdownHasFinished_Implementation()
{
CountdownText->SetText(TEXT("GO!"));
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "QuickStart.h"
#include "HealthActor.h"
// Sets default values
AHealthActor::AHealthActor()
{
// 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;
health = 100.0f;
}
void AHealthActor::reduceHealth()
{
health -= 20;
UE_LOG(LogTemp, Warning, TEXT("health %f"), health);
GetHealth();
}
float AHealthActor::GetHealth()
{
UE_LOG(LogTemp, Warning, TEXT("health %f"), health);
return health;
}
// Called when the game starts or when spawned
void AHealthActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AHealthActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
Now in my blueprint I do this for countdown
What I want to know is
now in this blue print, how can I call the reduce health to be reduced when countdown is finished,
and if I want to do it in code, what is the way to do this, because i tried to create health object in countdown this way
AHealthActor* myhealth;
myhealth->health = 100.0f;
but it crashed the system.
also if you have links that will get me going, please put them here too, because I have read all unreal programming guide, but still though I am confused, it would help to have more sources to read from
thanks for your help,