using UnityEngine; namespace InfinityCode.OnlineMapsSupport { public class RotateCameraByCompassExample2 : MonoBehaviour { public float duration = 1; private OnlineMapsCameraOrbit cameraOrbit; private float fromAngle; private float toAngle; private float progress = 1; private void Start() { OnlineMapsLocationService.instance.OnCompassChanged += OnCompassChanged; cameraOrbit = OnlineMapsCameraOrbit.instance; } private void OnCompassChanged(float f) { progress = 0; fromAngle = cameraOrbit.rotation.y; toAngle = f * 360; } private void Update() { if (progress >= 1) return; progress += Time.deltaTime / duration; if (progress > 1) progress = 1; float angle = Mathf.LerpAngle(fromAngle, toAngle, progress); cameraOrbit.rotation = new Vector2(cameraOrbit.rotation.x, angle); } } }