How to Place Objects on the Map
Prerequisites
- You will need a new 3D (URP) Unity project with Lightship Maps installed. For instructions, see Installing the Lightship Maps SDK.
Steps
- 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.
- Add your new MapLayer prefab or GameObject to the Map Layers list in the scene’s LightshipMapView.
- Set the Prefab field in the LayerGameObjectPlacement component to the prefab or GameObject that will be instantiated.
-
Serialize a reference to this LayerGameObjectPlacement component from where it will be used in code.
[SerializeField]
private LayerGameObjectPlacement _objectSpawner; -
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);