Make them interactive

Now that we have two animated rectangles, we will make them interactive with the GGV that we talked about earlier in this chapter. In order to do this, we will first set up our Mecanim nodes and the parameter that we need for them to work.

Once this is done, we will write our first C# script. It will be a very simple script, and since we will not be covering script writing just now, only the very basics will be explained.

If you do not currently have an Animator view open, with LeftRect selected in our Hierarchy view, click on Window followed by Animator to bring this window up:

As mentioned in the preceding section, you can see our nodes for the LeftRect.GameObject. The green node is our entry point. This node connects directly to LeftRectIdle, our default animation. We will be connecting our Entry node to our LeftRectMove as well. To do so, perform the following steps:

  1. First, right-click on the Entry node and click on Make Transition:
  1. A gray arrow and line will appear beneath your cursor. Move your cursor to the LeftRectMove node and click on it; the line will darken to let you know that it is set:
  1. Select RightRect in the Hierarchy view and repeat steps 1 and 2.

Now, we will need to rename the states. Let's perform these steps:

  1. Click on LeftRectIdle.
  2. In the Inspector, change the name to RectIdle:
  1. Click on LeftRectMove.
  2. In the Inspector, change the name to RectMove.
  3. Repeat these steps for RightRect also.

Simple so far, right?

Now, we need to set up our parameter so that our script can do its job:

  1. On the Parameter side of the Animator view, ensure that Parameters is highlighted; click on the plus sign:
  1. When the list of options appears, click on Bool.
  2. Type in idle as the name of the parameter.
  3. Then, idle will appear in the Parameters list with a checkbox next to it. Click on the checkbox and ensure that it is checked:
  1. Now, repeat these steps for RightRect.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.136.235