Hey Guys, I’ve been trying to make a clickable button with a texture on it in C++. So far all I have is the ability to make a basic texture in hud. How would I make a clickable
Here’s what I have so far on my HUD class
THE .h FILE/////////////////////////////
#pragma once
#include “GameFramework/HUD.h”
#include “MyHUD.generated.h”
/**
*
*/
UCLASS()
class SIGNTUTORIAL_API AMyHUD : public AHUD
{
GENERATED_UCLASS_BODY()
virtual void DrawHUD();
private:
UTexture2D* CrosshairTexture;
void DrawCrosshair();
};
THE CPP FILE/////////////////////////////////////////
#include “SignTutorial.h”
#include “MyHUD.h”
AMyHUD::AMyHUD(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTextureObject(TEXT(“Texture2D’/Game/crosshair.crosshair’”));
if (CrosshairTextureObject.Object)
{
CrosshairTexture = CrosshairTextureObject.Object;
}
}
void AMyHUD::DrawHUD()
{
Super::DrawHUD();
if (CrosshairTexture)
{
DrawCrosshair();
}
}
void AMyHUD::DrawCrosshair()
{
float TextureWidth = CrosshairTexture->GetSurfaceWidth();
float TextureHeight = CrosshairTexture->GetSurfaceHeight();
FVector2D const CanvasCenter(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
FVector2D const DrawPosition(CanvasCenter.X - TextureWidth * 0.5f, CanvasCenter.Y - TextureHeight * 0.5f);
FCanvasTileItem TileItem(DrawPosition, CrosshairTexture->Resource, FLinearColor::White);
TileItem.BlendMode = ESimpleElementBlendMode::SE_BLEND_Translucent;
Canvas->DrawItem(TileItem);
}