Switching between multiple options with one button

Hi all!

How would it be possible to change the line thickness in Ray Tracing with just pressing one button again and again?

I imagine something like this:

  1. Gameplay starts, trace lines are hidden (this works).
  2. Press “zero” button (or any other), and trace lines are displayed with 1 unit of thickness.
  3. Press “zero” button again, and trace lines are displayed in a thicker version, with 2 units of thickness.
  4. Press “zero” button again, and trace lines are displayed in a thicker version, with 3 units of thickness.
  5. If I press the button again, trace lines are not displayed.

Here is my code snippet:

in header:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Linetrace")
bool DebugLineSwitch;

in cpp:

// If DebugLineSwitch is turned On, rays are deisplayed during simulation
	int LineThickness = 0;

	if ((DebugLineSwitch == true) && (LineThickness = 0))
	{
		DisplayRays(LoopNumber + 1, TraceStart, TraceEnd, RayColor, LineThickness = 1);
		//DebugLine: //GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Green, FString::Printf(TEXT("Great!")));
	}

	else if ((DebugLineSwitch == true) && (LineThickness = 1))
	{
		DisplayRays(LoopNumber + 1, TraceStart, TraceEnd, RayColor, LineThickness = 2);
	}

	else if ((DebugLineSwitch == true) && (LineThickness = 2))
	{
		DisplayRays(LoopNumber + 1, TraceStart, TraceEnd, RayColor, LineThickness = 3);
	}

Any help is appreciated.

Will this work for you?

// .h
bool DebugLineSwitch = true;
int LineThickness = 0;
int MaxLineThickness = 4;
void ToggleLineThickness();
// .cpp
// InputAction bound to this:
void AMyPawn::ToggleLineThickness()
{
	LineThickness = (LineThickness + 1) % (MaxLineThickness + 1); // 0, 1, 2, 3, 4, 0...
}

// Condition to draw the debug line.
if (DebugLineSwitch && LineThickness != 0)
{
	DrawDebugLine(GetWorld(), TraceStart, TraceEnd, RayColor, false, 1.f, 0, LineThickness);
}