The location-based game example shows how to position and orient a
Player GameObject on a map using a GPS device or using the editor directly. The scene set a pin on a 2D map that includes building outline data and other procedurally generated geo features from Mapbox’s data that you can toggle and style as needed. This example uses a custom map style from Mapbox Studio, but it can be swapped with any other map style.
Player GameObject is a 3D model representing the player’s location on the map.
Player moves and rotates along with
LocationProvider, a GameObject that captures real or simulated location.
Any GameObject can represent the player in this scene. To use a different 3D model:
- Remove the original
Playerobject, add the new model into the scene, and position it at
- Add the
Immediate Position With Location Providerand
Rotate With Location Providercomponents to this GameObject.
- Attach the Map object to the Map field in
Immediate Position With Location Provider.
- The custom
Playerwill show up on the map and be able to move.
LocationProvider GameObject holds a collection of scripts to determine a player’s location, either in the real world (with GPS, on a device) or simulated in Unity (with manually added coordinates). Without these scripts, the location would be hard-coded in the
There are several different Location Provider scripts:
DeviceLocationProvider: Uses GPS data on a device. The
PlayerGameObject follows the location on the map reported by the GPS device update.
EditorLocationProvider: Is like
DeviceLocationProvider, but for testing inside Unity.
LocationArrayEditorLocationProvider: Allows the
PlayerGameObject to be moved across a set of points entered as latitude, longitude coordinates in an array.
TransformLocationProvider: Makes the
PlayerGameObject follow the position and rotation of another GameObject.
DeviceLocationProviderAndroidNative: Uses GPS data optimized for Android devices.
With the Location Based Game example, you can create a zoomable, pannable map that a
Player can move around. Use it to look at real world map data from a top-down view, like a paper map. But, it is not ideal for building 3D scenes with a more flexible camera view. This is like the Zoomable Map example, which acts similarly to Location Based Game, but does not have a