Skip to main content

How to Place Objects on the Map

Prerequisites

  1. You will need a new 3D (URP) Unity project with Lightship Maps installed. For instructions, see Installing the Lightship Maps SDK.

Steps

  1. Create a new GameObject Placement Layer prefab from the Create Asset menu. Alternatively, create a new GameObject with a MapLayer component and at least one LayerGameObjectPlacement component.
Map Layer Prefabs menu
  1. Add your new MapLayer prefab or GameObject to the Map Layers list in the scene’s LightshipMapView.
Map Layer Prefabs menu
  1. Set the Prefab field in the LayerGameObjectPlacement component to the prefab or GameObject that will be instantiated.
Map Layer Prefabs menu
  1. Serialize a reference to this LayerGameObjectPlacement component from where it will be used in code.

    [SerializeField]
    private LayerGameObjectPlacement _objectSpawner;
  2. Call the PlaceInstance() method to place an instance of this object on the map.

    var location = ScreenPointToLatLong(touchPosition);
    var cameraForward = _mapCamera.transform.forward;
    var forward = new Vector3(cameraForward.x, 0f, cameraForward.z).normalized;
    var rotation = Quaternion.LookRotation(forward);

    _objectSpawner.PlaceInstance(location, rotation);