Step 5 – Tree time

Now that we have a fully textured island, we need to spruce up the place a little with some trees. In our TerrainAssets package, there is a tree provided to get us started with the Terrain Editor and, thankfully for us, it is a palm tree asset.

There is a Tree creator available in Unity, which you should try when you've finished this book, once you have more experience in Unity. For more information on this, visit: http://unity3d.com/support/documentation/Components/class-Tree.html.

For now, we will make use of the palm tree we have already created. Select the Place Trees tool of the Terrain(Script) component and click on the Edit Trees button. From the drop-down menu that appears, choose Add Tree.

The Add Tree dialog window will appear. As with some of the other terrain tools, this add dialog allows us to select any object of an appropriate type from our Assets folder.

This is not restricted to trees provided in Terrain Assets, which means that you can model your own trees by saving them into the Assets folder of your project in order to use them with this tool (see the documentation on trees for further details). However, we are going to use the Terrain assets provided by the palm tree. Click on the circle selection button to the far right of the Tree setting. As with the texture painting earlier, this will open an asset selection window from which you can choose the Palm tree.

Bend factor here allows our trees to sway in the wind. This effect is computationally expensive, and any value will likely incur a performance reduction when play testing your game. If you experience poor performance, return to this setting and replace it with a value of 0. For now, we'll simply use a low number for a small amount of tree sway, so type in a value of 2 and press Enter to confirm. If you find that this is causing low performance later in the development, then you can always return to this setting and set it back to 0. Click on the Add button to finish:

With your palm tree in the palette, you should see a small preview of the tree with a blue background to show that it is selected as the tree to place on the terrain.

Set Brush Size to 15 (painting 15 trees at a time) and Tree Density to 40 (giving us a wide spread of trees). Set Color Variation to 0.4 to give us a varied set of trees and Tree Height / Width to 50 with their Variation settings at 30.

Using single-clicks, place trees around the coast of the island, near the sandy areas that you would expect to see them. Then, to complement the island's terrain, place a few more palm trees at random locations inland:

Remember that, if you paint trees incorrectly at any time, you can hold the Shift key and click, or paint (drag) with the mouse to erase trees from the terrain.