Help With Unity Project Animator and Code

Hey guys i apologize ahead of time if this is not the right place to post this but i wasn’t sure where to ask. Im having an issue with a project. I am working on a very small old style 2D Turn RPG with a sort of timer mechanic. Basically there is a wheel that shows various moon phases, and the phase is supposed to change after both the player and the enemy attacks. The issue i am having is once the enemy attacks and activates the function that is suppose to make the phase of the moon change by 1 phase, the phase selector will change by several phases as if it doesnt register the animation event on the animator. Below is a video of what the error looks like as well as images of the relevant code. I have tried using “enable = false /true” as well as “speed = 1/0” any help would be greatly appreciated

Video of Bug
https://youtu.be/TzlCuxaAzBA

Code

Animator

Each animation event is the same bit of code

I have a couple of other scripts but none of them reference the animator or the change in the phase selector. if they are needed though please let me know and i will post them

thank you!

Hi Kaylee,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? From what I see, you are using the Update method with a specific condition. You could try to figure out how often the concerning code blocks get called. Maybe your animation event works but the output is unexpected because something else starts the animation again. Never assume that something works. Always verify it. Then you’ll eventually find the root of the problem.

Hope this helps :slight_smile:


See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms