Time for action – Implementing the joysticks

  1. Expand the Standard Assets (Mobile) unitypackage that we added to the project initially in one part of our solution. Inside of the Prefabs folder there is a Dual Joysticks prefab:
    Time for action – Implementing the joysticks
  2. Since this is going to be moving with the user interface plane of our camera we can simply make it a child of the camera:
    Time for action – Implementing the joysticks
  3. Set the Game view to display in iPhone Wide by selecting the dropdown in the upper left of the Game view. This will result in a more accurate depiction of how the game will look at startup. Now, when we take a look at the Game view we can see exactly what our camera will see when our game starts:
    Time for action – Implementing the joysticks

This figure represents what we expect to see – our two Joystick nubs in the user interface ready for user interaction. If you start your application on your iOS device you will see that as you place your fingers over the joystick nubs, they will move around as your fingers manipulate them during a touch. When you remove your finger from the nub it will snap back to the center position. This information is captured by the Prefab and passed off to the built-in Joystick script.

To pass the input to some other script, simply alter the script that the Prefab is pointing to. Note that each Joystick can have its own script so you can have two entirely different behaviors per joystick.

You can also change the texture that the joystick uses by updating the Texture field on the GUITexture which represents the joystick:

Time for action – Implementing the joysticks

What just happened?

We have just implemented the primary means of input for our game – the dual joystick nubs. As we move these joysticks around they relay data to the Joystick script. While this is interesting, it still doesn't move our character around the scene. If all we needed were some basic joystick processing we'd be done, but we need to control a character and move our camera around the scene. Fortunately, there's a prefab for that.

..................Content has been hidden....................

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