Here is the Game Plan
Before moving ahead, I want to give a quick rundown of what we are doing. We have an object with two animation states: idle and moving. Idle is the default mode. We have created an idle parameter with the checkbox checked, which makes the condition true.
In the next section, we will write a script that has the following two main functions:
- If the object is selected, it changes idle from true to false or vice versa
- In the update function, it checks for two conditions: whether idle is true or false and to play the correct animation
When the application loads, you will see the two boxes; because idle is the default state, nothing will happen until they are selected. Once they are, they will move. If they are selected again, they will go idle once more:
- With
LeftRect
selected in theHierarchy
view, search for theInspector
panel, scroll to the bottom, and click onAdd Component
:
- Scroll down to
New Script
and select it. - Name the new script
RectAnim
:
- Click on
Create and Add
.
For the...