Intermediate Unity 3D for iOS: Part 3/3

This is a tutorial by Joshua Newnham, the founder of We Make Play, an independent studio crafting creative digital play for emerging platforms. Welcome back to our Intermediate Unity 3D for iOS tutorial series! In the first part of the series, you learned how to use the Unity interface to lay out a game scene, […] By .

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Build and Run

As you did before, open the Build dialog via File -> Build Settings, and click on the build button to test your finished game!

Build and run the Xcode project, and you should see a beautiful working menu on your device!

Finished game on the iPhone.

w00t you've got a complete simple Unity 3D game! :]

Optimizations

A book could be written about optimizing your app! Even if you think the performance is acceptable, consider that there are a LOT of old iPod touches and iPhone 3G models out there. You've worked hard to make a game, and you don't people with older devices to think your games are laggy!

Here's a list of items to keep in mind when developing:

  • Keep draw calls to a minimum — You should aim to keep your draw calls as minimal as possible. To achieve this, share textures and materials, and avoid using transparent shaders — use mobile shaders instead. Limit the number of lights you use, and always use a texture atlas for your HUD.
  • Keep an eye on the complexity of your scene — Use optimized models, meaning models with minimal geometry. Instead of using geometry for the details, you can usually achieve the same effect by baking the details into the textures, similar to how you would bake in lighting. Remember that the user is only staring at a small screen, so a lot of detail won’t be picked up.
  • Fake the shadows with the model — Dynamic shadows are not available in iOS, but projectors can be used to mimic shadows. The only issue is that projectors drive up your draw calls, so if possible, use a flat plane with a shadow texture that uses a a particle Shader to mimic the shadow.
  • Be wary of anything you place in your Update/FixedUpdate methods — Ideally the Update() and FixedUpdate() calls run 30 to 60 times per second. Because of this, ensure that you calculate or reference everything possible before these are called. Also be wary of any logic you add to these modules, especially if they are physics related!
  • Turn off anything you’re not using — If you don’t need a script to run, then disable it. It doesn’t matter how simple it appears to be – everything in your app consumes processor time!
  • Use the simplest component possible — If you don’t require most of the functionality of a component, then write the parts you need yourself and avoid using the component altogether. As an example, CharacterController is a greedy component, so it’s best to roll your own solution using Rigidbody.
  • Test on the device throughout development — When running your game, turn on the console debug log so you can see what may be eating up processor cycles. To do this, locate and open the iPhone_Profiler.h file in XCode and set ENABLE_INTERNAL_PROFILER to 1. This gives you a high-level view of how well your app is performing. If you have Unity 3D Advance, then you can take advantage of the profiler which will allow you to drill down into your scripts to find how much time each method is consuming. The output of the internal profiler looks something like the following:
  • frametime gives you an indication of how fast your game loop is; by default this is set to either 30 or 60. Your average should be hitting somewhere near this value.
  • draw-call gives you the number of draw calls for the current render call - as mentioned before, keep this as low as possible by sharing textures and materials.
  • verts gives you an snapshot of how many vertices are currently being rendered
  • player-detail gives you a nice overview of how much time each component of your game engine is consuming

Where To Go From Here?

Here is a sample project with the complete finished game from this tutorial series. To open it in Unity, go to File\Open Project, click Open Other, and browse to the folder. Note that the scene won't load by default - to open it, select Scenes\GameScene.

You’ve done well to get this far, but the journey doesn’t stop here! :] Hopefully you will keep up the momentum and become a Unity ninja; there is definitely a lot of demand for these types of skills at the moment!

Here are a few suggestions of how you can extend your game:

  • Add sound. Sound is extremely important for any interactive content, so spend some time looking into sound and music and add it to the game.
  • Hook up Facebook so users can compete with friends.
  • Add multiplayer mode, which will allow users to play against each other on the same device, where each player takes turns throwing.
  • Add new characters to allow the user to personalize the game.
  • Extend the user input to allow different gestures, and then use these gestures to implement different types of throws.
  • Add bonus balls, with each ball having different physical attributes, such as increased gravity.
  • Add new levels, with each level being ever more challenging!

That should be enough to keep you busy! :]

I hope you enjoyed this tutorial series and learned a bit about Unity. I hope to see some of you create some Unity apps in the future!

If you have any comments or questions on this tutorial or Unity in general, please join the forum discussion below!


This is a tutorial by Joshua Newnham, the founder of We Make Play, an independent studio crafting creative digital play for emerging platforms.