Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by bluenell · Apr 30, 2020 at 01:44 PM · inputlooping

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Clairvoyantindie · Apr 30, 2020 at 02:14 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bluenell · Apr 30, 2020 at 03:02 PM 0
Share

Hello,

The game doesn't loop if the player doesn't respond when there is a bite. It does loop if they respond too late or if they are successful with their catch though.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

225 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input.GetKeyDown(...) loop glitches 2 Answers

If Statement within a while loop only checks the if condition once. 0 Answers

PointAndClick 1 Answer

How use ANDROID NAVIGATION BUTTONS 0 Answers

Touch Controls without virtual joystick 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges