Skip to main content

How to Place Object Using a Maplayer

You will use Maplayers to add GameObjects on top of the LightshipMap. Those objects will stay where they are placed on the map even as the map moves. These steps demonstrate how to add an object to a new layer using a LayerGameObjectPlacement.

Prerequisites

  1. You must have a Unity project with the Lightship Maps package installed and a LightshipMaps prefab added to a scene. See Getting Started with Lightship Maps if you have not done that yet.

Steps

  1. Add a new MapLayer prefab.

    1. Under the Project tab, select the Assets folder.

    2. From the menu, select Assets > Create > Maps SDK > Map Layer Prefabs > GameObject Placement Layer.

    3. Select a name for the layer and press Enter.

    4. Drag and drop the new MapLayer prefab to the scene. In the image below it is added as a child of the LightshipMaps game object but it will work as long as it’s somewhere in the scene.

      New Map Layer
  2. Add your GameObject to the prefab.

    1. Go to the Inspector view for the MapLayer.

    2. Under Layer Game Object Placement (Script), add your GameObject under Prefab.

      Layer Game Object Placement
  3. Add the MapLayer prefab to the LightshipMaps prefab.

    1. Go to the Inspector view for the LightshipMaps prefab.

    2. Under MapLayers, click + to add a new layer.

    3. Select your new MapLayer.

      LightshipMap - MayLayers
  4. Instatiate your GameObjects in a script.

    1. In the script where you plan to instantiate the GameObject, create a new LayerGameObjectPlacement serializable field:

      [SerializeField] private LayerGameObjectPlacement _cubeGOP;
    2. In the method where you instantiate the object, call LayerGameObjectPlacement.PlaceInstance() to place the object on the map. You will need to pass in the object's position (in LatLng) for it to instantiate in the correct position on the map.

      private void PlaceObject(LatLng pos) => _cubeGOP.PlaceInstance(pos);
      LightshipMap - MayLayers