From 1c585138710520def5f09c10ec790dd5a8c43d44 Mon Sep 17 00:00:00 2001 From: Jai Dhyani Date: Tue, 5 Oct 2021 19:31:05 -0700 Subject: [PATCH] Fix SpawnOnMap objects not scaling on zoom The current implementation never sets a parent, so the references to local position and scale in the `Update` function just refer to global position and rotation. This change sets the `AbstractMap _map` as the parent of the newly instantiated object and sets local scale according against that. For position we set global instead of local position because `GeoToWorldPosition` returns the global position. --- .../Mapbox/Examples/6_ZoomableMap/Scripts/SpawnOnMap.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Examples/6_ZoomableMap/Scripts/SpawnOnMap.cs b/sdkproject/Assets/Mapbox/Examples/6_ZoomableMap/Scripts/SpawnOnMap.cs index 0b7042f68..7f0b52867 100644 --- a/sdkproject/Assets/Mapbox/Examples/6_ZoomableMap/Scripts/SpawnOnMap.cs +++ b/sdkproject/Assets/Mapbox/Examples/6_ZoomableMap/Scripts/SpawnOnMap.cs @@ -36,6 +36,7 @@ void Start() var instance = Instantiate(_markerPrefab); instance.transform.localPosition = _map.GeoToWorldPosition(_locations[i], true); instance.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale); + instance.transform.SetParent(_map.transform); _spawnedObjects.Add(instance); } } @@ -47,9 +48,9 @@ private void Update() { var spawnedObject = _spawnedObjects[i]; var location = _locations[i]; - spawnedObject.transform.localPosition = _map.GeoToWorldPosition(location, true); + spawnedObject.transform.position = _map.GeoToWorldPosition(location, true); spawnedObject.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale); } } } -} \ No newline at end of file +}