Fishing mini game automatically restarting and not working as intended

I’m creating a fishing mini-game as part of my project. The rules are that when the player is in a certain location (near water) they can press E to cast their line and then wait a random length of time before a fish bites. They then have to press E again within a short time frame in order to catch the fish. Finally, they are given the choice to keep the fish or throw it back in the water. If they press E again within a larger time frame they can keep it if they wait too long, it gets thrown back in.


This whole process does work, however, the issue comes across when the sequence has finished or been cancelled due to the player failing the mini-game.

As this is part of a much larger project, I’m using a big if statement to check certain conditions when the player presses E. One of these conditions are what’s required to go fishing. When the condition is met, a bool is set to true to notify another script that I want to run the “Fishing” method.


From what I can tell, despite this code being told to only run under this condition, and me explicitly writing “usingRod = false” whenever the game ends or is cancelled, the mini game loops again, leaving the player stuck in an endless game of fishing.

I understand that this is probably not the most efficient way of detecting input and running a minigame but it’s worked fine so far so haven’t really needed to change anything.

Here’s the fishing method:

public void Fishing()
{
    if (playerController.usingRod)
    {
        playerController.DisablePlayerInput();

        if (fishStage == 0)
        {
            playerAnimator.SetTrigger("fishing_cast");

            Debug.Log("waiting for bite");

            if (!generated)
            {
                random = Random.Range(randomWaitTime.x, randomWaitTime.y);
                generated = true;
            }

            timer += Time.deltaTime;

            if (timer >= random)
            {
                Debug.Log("Bite");
                playerAnimator.SetTrigger("fishing_bite");
                timer = 0;
                generated = false;
                fishStage = 1;
            }
            else if (timer < random && Input.GetKeyDown(KeyCode.E))
            {
                Debug.Log("reel too early");
                playerAnimator.SetTrigger("fishing_fail");

                CancelInteraction();
            }
        }
        else if (fishStage == 1)
        {
            timer += Time.deltaTime;

            if (timer < 1f && Input.GetKeyDown(KeyCode.E))
            {
                playerAnimator.SetInteger("fishing_randomIndex", Random.Range(1, 5));
                Debug.Log("caught");
                timer = 0;
                fishStage = 2;
            }
            else if (timer > 1f && Input.GetKeyDown(KeyCode.E))
            {
                playerAnimator.SetTrigger("fishing_fail");
                CancelInteraction();

            }
            else if (timer > 2f)
            {
                playerAnimator.SetTrigger("fishing_fail");
                CancelInteraction();

            }
        }
        else if (fishStage == 2)
        {
            timer += Time.deltaTime;

            if (timer <= 5f && Input.GetKeyDown(KeyCode.E))
            {
                playerAnimator.SetTrigger("fishing_keep");
                CancelInteraction();

            }
            else if (timer >= 5f)
            {
                playerAnimator.SetTrigger("fishing_throw");
                CancelInteraction();

            }
        }
    }

}

Here’s the condition to set usingRod to true in the large if statement being called in Update()

(This is nested within an Input.GetKeyDown() check)

if (currentInventoryIndex == 2 && interactionsManager.interaction.requiredTool == 2)
{
        usingRod = true;

}

Here is the if statement that runs the interaction code if usingRod = true

else if (playerController.usingRod)
            {
                if (playerController.currentInventoryIndex == 2)
                {
                    if (interaction.interactionName == "Fishing")
                    {
                        indivInteractions.Fishing();
                    }
                }
            }

I appreciate this is a long post however I’ve been stuck on this for a while now and due to covid, I’m struggling to contact my peers to get their help too!

Many thanks for any feedback, and if there’s any more information required let me know! Jamie

does the game loop when the player fails the game ? or it is happening in both cases winning and failing?