Animator and animation. Log #6 (Unity)

          In previous log I mentioned lines anim.SetBool, now I will return to them. My character has some clips (animations). I need to run these animations at exact moments as they are in the code. Component Animator in Unity controls animation clips (Window>Animator NOT Animation). Animator has start state and finite state as default, any clip or animation is another state. Between these states are transitions and these are based on conditions.

          In the assets I create new folder Controllers. In the folder right click and select Animator Controller. Drag created controller to component Animator in inspector to the Controller field. When I click in the assets on my characeter model there are the clips I created in previous log.




          I just drag the clips Idle and Run to Animator window. That creates two states and automaticaly creates transition between Start and Idle. If I start game now, the character state changes to Idle but never ends that state. That is, because I did not define other transitions. Right click on Idle state and select Make Transition, then left click on state Run for creating new transition. I will do the same for transition back. The player character won't still run though, because the Animator don't know when to make a transition. In the left top corner is panel Paramateres and near the search field is small symbol "+". Click on the symbol and choose Bool. That creates new parameter that I will name "Run". In this panel are parameters that I refer to functions SetBool(), SetFloat(), etc... These functions have two parameters, one is name of the parameter in the Animator, the second is a value of it. Now I can set conditions which will run the transitions. Clicking on transition Idle>Run opens options in inspector, at the bottom is field Conditions. Click on "+" symbol then select Run and true. That means if parameter Run is true the transition is activated. Also it is important to check the "Has exit time" checkbox, this causes, that the transition does not need to wait for finishing the previous state (animation). The same settings I do for the opposite transition.



In the next log I will focus on camera.