Optimizing the Animator and Callouts
Let’s take a look at how we can go about creating methods in which to utilize our animation transitions. When we go about coding some animations, we can take a longer process and code each individual transition that happens like so:
However, do it this way becomes rather tedious and if you have more than a couple different animations, it will take a long time to go about creating all of the required transitions. Instead, let’s look at how we can go about and index the transitions so that we can simplify the process:
By doing it this way, what we are able to do is determine by Int value, the different values each stage will be at. This allows us a much easier way of coding in the transitions into the program:
Now that we have our horse animation transitioning as intended, let’s take a look at how we can go about creating the callout that shows up when we go to the muscle:
First, we need to create a target and the start position. On our start position, which will be a label, we are going to add in the line renderer component. This will allow us to draw a line from the start position to the target position. Next, we will want to make sure that it is a thin line, so we shrink down the width on either end to 0.1. Now, in order to create the method in which we have our line appear and disappear at the proper moment, we will need to code it within our UIManager:
With this logic, we are telling Unity that we want it so that when the value of our currentAnim is set to 1, we will enable our label which will then activate the line between the points. However, if the value of it is not 1, we want the label to be disabled so that it doesn’t stay up there forever. With all of this set up, and everything attached to where it should be within Unity, let’s take a look at what it looks like within the program:
As we can see, the label shows up when we go into our muscle image and when we go to a different state, we have our label disappear again.
There we have it, we’ve looked at how we can index our animation transitions along with creating a callout and having it appear during a specific animation.