Beginning Unity 3D for iOS: Part 2/3
In this second tutorial,, you’ll add functionality to enrich the project, including better player movement and better game scenery. You’ll also learn how to use Unity Remote for debugging. By Christine Abernathy.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Beginning Unity 3D for iOS: Part 2/3
20 mins
Don’t Forget Your Veggies
Switch back to the Scene View. You can create vegetation by first adding a terrain GameObject, then adding material (e.g., grass) and objects (e.g., trees).
You no longer need the plane GameObject, as the terrain will take over flooring responsibilities. Right-click on the plane GameObject in the Hierarchy View and select Delete.
Select Assets\Import Package\Terrain Assets.
Click Import to import all the selections. The Terrain Assets should show up under your Standard Assets folder. You can use the imported assets to modify the behavior of a terrain GameObject.
Select Terrain\Create Terrain to add a terrain GameObject to your scene. Select the terrain object and change its transform position to -1000,0,-1000 using the Inspector. This stretches the terrain out far enough to give your player room to move.
The Terrain (Script) section contains tools that you can use to dress up your terrain:
Select the Paint tool to bring up the brushes you can work with:
You’ll be painting your terrain with grass. Click Edit Textures\Add Texture:
In the Add Terrain Texture dialog, click Select in the Texture area, select the Grass (Hill) texture, close the Select Texture2D pop up, then click Add:
Click around in your scene to paint the grass. To check out your artwork, click on the Game tab:
If only landscaping could always be so easy!
Switch back to the Scene View – now you’re going to plant some palm trees! Select the Place Trees tool in the Terrain (Script) section:
Click Edit Trees\Add Tree:
In the Add Tree dialog, click the circular icon next to the Tree entry, select the Palm GameObject, then click Add:
Set the Brush Size to 20:
Start adding trees to your scene by clicking where you want the trees to be. Hint: Zoom into the scene and pan around as you place the trees. Try adjusting the Point light range and height to see more of the scene as you add trees.
When done, your scene should look something like this:
Wow, that’s much better! It’s starting to look like a real world down there. But your terrain’s still looking a bit flat, isn’t it?
You can easily add some height variation to your terrain. In the Terrain (Script) section, select the leftmost tool to raise and lower the terrain height:
Set the Brush Size to 20, then in the Scene View, click on two to three spots around the player (not too near, though) to vary the terrain height.
Preview the game and move around the scene. Tweak the number of trees in the scene as you see fit but remember to stop the game before making any changes you wish to keep.
Save your scene.
Test your project using Unity Remote and when satisfied, build it as an Xcode project. Select File\Build Settings and in the Build Settings dialog, click Add Current to add the Level_2 scene. The new scene will show up in the Scenes In Build list. Deselect the Level_1 scene to build only Level_2.
Click Build, choose to replace the previous project if asked and then launch the Xcode project. Deploy and test on your iOS device.
Not bad, eh? Imagine how long it would have taken to do all this with raw OpenGL ;]
Where to Go From Here?
Well done! You’ve taken another big stride forward in developing your Unity skills. :] Soon, your Heroic Cube will be closing in on the finish line, too.
Here are some downloads with all of the code from the project up until this point: Unity Project, Xcode Project.
In the final part of the tutorial, you’ll build on the project by adding gameplay. Then you’ll polish it up by adding all the bells and whistles that players expect.
How do you like Unity so far? We’d love to hear about your experiences in the forums!