Maps Unity SDK Example Scenes

The Maps Unity SDK ships with a collection of example Unity scenes, and each one demonstrates a fundamental feature of the SDK. They're installed when you install the SDK, into the /GoogleMaps/Examples/ directory.

To run an example scene in Unity

  1. Integrate the Maps Unity SDK by following the Getting Started procedure. When you're done, you'll have downloaded the SDK, and integrated it into Unity.

  2. Create a new Unity project.

  3. In the Project pane, navigate to and select the /Assets/GoogleMaps/Examples/ folder. The example scenes appear inside the Project content pane.

  4. Double-click the example scene that you want to run. The scene appears in the Hierarchy pane.

  5. Click the Run button.

Basic example

This example scene demonstrates the most rudimentary aspects of the Maps Unity SDK. By default, it loads the coordinates for the Statue of Liberty, and then displays the Statue of Liberty GameObject and surrounding geometry, in both the Scene and Editor panes.

If you stop the scene, you can then enter a new set of coordinates into the Latitude and Longitude fields (inside the Basic Example (Script) component in the Inspector), and then re-run the scene—and a different world-scene will display.

Dynamic loading

This example scene demonstrates how to use the DynamicMapsService component—which keeps the Camera.main viewport loaded at all times, unloading everything outside the viewport.

By default, this example loads the coordinates for Melbourne, Australia. If you stop the scene, you can then enter a new set of coordinates into the Latitude and Longitude fields (inside the Dynamic Maps Service Script) component in the Inspector), and then re-run the scene, and a different world-scene will display.

Error handling

This example scene demonstrates how to use the Error Handling component—which handles and debugs errors encountered by the SDK. The Error Handling component handles the most common errors, giving specific error messages in these cases, otherwise it just shows the error message sent from the SDK.

Floating origin

This example scene demonstrates how to use the MapsService.MoveFloatingOrigin method to re-center the gameworld. This becomes necessary because of floating-point rounding errors, which cause map features to be increasingly misplaced the further gameplay moves away from the game origin. For more information, see Floating Origin.

Nine-slicing

This example scene demonstrates how to texture buildings using nine-sliced materials. It uses the BuildingTexturer component to apply nine-sliced materials, and it uses the DynamicMapsService component to allow navigation around the world, with the MapsService component keeping only the viewed part of the world loaded at all times.

This example also uses the ErrorHandling component to display any errors encountered by the MapsService component when loading world geometry.

Road borders

This example scene demonstrates how to use the SDK's two-stroke roads to visually blend roads into surrounding grounds.

By default, this example scene loads the roads around the Statue of Liberty. It also uses the ErrorHandling component to display any errors encountered by the MapsService component when loading world geometry.

Road widths

This example scene demonstrates how to set road widths according to the type of road.

This example scene uses the DynamicMapsService to allow navigation around the world, with the MapsService keeping only the viewed part of the world loaded at all times. This example also uses the ErrorHandling component to display any errors encountered by the MapsService component when loading world geometry.

Building borders

This example scene demonstrates how to add borders around the bases of buildings.

This example is almost identical to the nine-slicing example. The only difference is that this example uses the Extruder class to add modelled borders to the bases of buildings.

This example also uses the DynamicMapsService component, the BuildingTexturer component, and the ErrorHandling component.

Parapets

This example scene demonstrates how to add parapets to the top edge of buildings.

This example is almost identical to the nine-slicing example. The only difference is that this example uses an Extruder to add modelled parapets around building roofs. It also uses the DynamicMapsService component, the BuildingTexturer component, and the ErrorHandling component.

By default, this example loads the coordinates for Melbourne, Australia.

Day and night

This example scene demonstrates how to create a day-night cycle using Unity's skybox system, directional lighting, and emissive materials.

This example is almost identical to the nine-slicing example. The only difference is that this example adds a SunAndMoonController and an EmissionController to control the lighting and emission-colors of materials to simulate a day-night cycle. The underlying logic of applying materials to buildings is the same as in the nine-slicing example.

This example also uses the DynamicMapsService component, the BuildingTexturer component, and the ErrorHandling component.

Level of detail

This example scene demonstrates how to setup LOD Groups with multiple MapsServices loading different MapsService.ZoomLevels.

This example also uses the ErrorHandling component to display any errors encountered by the MapsService component when loading geometry.

By default, this example loads the coordinates for Manhattan, in New York City.

Search by place ID

This example scene demonstrates how to use the SDK's DidCreate event to find and alter elements by placeId.

By default, this example loads the coordinates for Tokyo Station, and it reduces the station's height to four floors. This example also uses the ErrorHandling component.

Prefab replacement

This example scene demonstrates how to use a defined prefab to replace buildings of given types, or to replace buildings suppressed by the SDK because they have a vertex count that exceeds Unity's maximum supported vertex count (65,000 vertices per mesh).

When this scene opens, it focuses on Westminster Abbey (London), which appears replaced by a prefab because this particular model is too detailed for Unity to handle (and is therefore suppressed).

This example uses the ErrorHandling component to display any errors encountered by the MapsService component when loading geometry.

Playable locations

This example scene demonstrates how to call the PlayagbleLocationsService methods for reporting bad playable locations, and for logging impressions (by calling ReportInteractedPlace() and ReportPresentedPlace() ) for two different types of GameObjects.

Adding a component

This example scene demonstrates how to add the MapsService component to a GameObject at runtime, and how to then alter its parameters (like MapsService.ZoomLevel) before the Awake() function is invoked.

By default, this example loads the coordinates for the Statue of Liberty. If you stop the scene, you can then enter a new set of coordinates into the Latitude and Longitude fields (inside the Adding Component (Script) component in the Inspector), and then re-run the scene—and a different world-scene will display.

Road names

This example scene demonstrates how to get and then display the names of the roads in the scene.

The Label Prefab used in this example contains a Text element that has a custom shader assigned to it. This shader ensures that this Text element is displayed on top of all in-scene geometry, even when it appears behind or inside the geometry. You can examine the shader on this prefab to see how this works.

This example uses the DynamicMapsService component, the RoadLabeller component, and the ErrorHandling component.

Building names

This example scene demonstrates how to get and display the name of a building.

The specific Label Prefab used in this example contains a Text element that has a custom shader assigned to it. This shader ensures that this Text element is displayed on top of all in-scene geometry, even when it appears behind or inside the geometry. You can examine the shader on this prefab to see how this works.

By default, this example loads the coordinates for the Tokyo Station.

Building squashing

This example scene demonstrates how to squash buildings (that is, reduce the height of extruded buildings to zero) when they are close to the player. This example uses the ErrorHandling component to display any errors encountered by the MapsService component when loading geometry.

Buildings over roads

This example scene demonstrates how to automatically remove buildings from on top of roads (including rails and ferry lanes).

This example uses the DynamicMapsService to allow navigation around the world, with the MapsService keeping only the viewed part of the world loaded at all times. It also uses a BuildingTexturer to apply nine-sliced materials, and it uses the ErrorHandling component to display any errors encountered by the MapsService component when loading geometry.

Custom zoom

This example scene demonstrates how to use the mapsService.MakeMapLoadRegion() method to load map features at a manually-defined zoom level. It uses the ErrorHandling component to display any errors encountered by the MapsService component when loading geometry.

Minimap

This example scene demonstrates how to set up a Camera's render setting to display a minimap view of the gameworld in a UI element. This scene uses a gameObject.layer and a Camera.cullingMask to control what's displayed in the minimap. This scene also uses a RenderTexture to connect to a UI.RawImage UI component for displaying as an on-screen minimap.

Location follower

This example scene demonstrates how to use the player's real-world GPS coordinates to update their gameworld position.

Loading bar

This example scene demonstrates how to use the LoadingBarController class to display the progress of the MapsService while it loads the gameworld.

Mixing zoom levels

This example scene demonstrates how to load different world locations at different zoom levels.

Load failures

This example scene demonstrates how to display an error icon over regions that fail to load.

Admin area coloring

This example scene demonstrates how to display an outline around administrative areas (currently only supported in Japan).

The kitchen sink

This example scene demonstrates the features demonstrated in most of the other example scenes—brought together into a single cohesive scene.