My method is being repeated several times during a single input.
My code is supposed to launch the cube once after the screen has been touched and it works other than the "Throw" action is repeated several times during the input so it is very inconsistent. The force of each "Throw" is different because it's working on an slider, but it repeats the "Throw" method several times during the single input. I'm looking for a way to stop the If statement (near the bottom of the first PNG) from collecting information after the first initial input/Throw or if there is a work around by only calling Throw once the input/finger is lifted from the screen.
I have a Debug.Log statement for whenever two certain cubes collide and for the force of each Throw method, so I'm 90% certain the problem is due to it calculating the input many times during the Update method or something along those lines.
Sorry if the explanation is off or formatted poorly as I'm very new to coding and the unity forums. Thanks in advance for any help or advice.
Answer by ytvampy · Aug 21, 2020 at 07:31 AM
I found a way to fix the problem for anyone having the same issue, you can just use a private boolean method to simply have true of false if the command already executed.
For example: private bool alreadyExecuted = false;
if (condition) { Method(); alreadyExecuted = true; }
Hope this helps anyone w/the same problem.