Just one bool for playing audio sound seems enough

Hi! Really enjoying the course so far.

One comment about that lecture. It seems to me one bool suffices:

OpenDoor.h

private:
	bool DoorIsOpen = false;

OpenDoor.cpp

void UOpenDoor::OpenDoor(float DeltaTime)
{
	if (!DoorActor) {return;}

	if (!DoorIsOpen && AudioComponent) {
		AudioComponent->Play();
	}
	DoorIsOpen = true
       // ...
}

void UOpenDoor::CloseDoor(float DeltaTime)
{
	if (!DoorActor) {return;}

	if (DoorIsOpen && AudioComponent) {
		AudioComponent->Play();
	}
	DoorIsOpen = false;
        // ...
}
5 Likes

You’re totally right! That’s what I did also in the challenge. I created a boolean called DoorIsOpening. Then in OpenDoor I have:

if (!DoorIsOpening) {
		OpenDoorSound->Play();
		DoorIsOpening = true;
	}

and in Close Door:

if (DoorIsOpening) {
	OpenDoorSound->Play();
	DoorIsOpening = false;
}
3 Likes

I’m glad someone else realized this too. Seemed like the way he did it made it way more complicated than it needed to be, and also way more confusing reading the code to figure out what’s going on

This makes more sense to me. Thank you for sharing!

Privacy & Terms