using UnityEngine; public class ChangePositionUsingGyro:MonoBehaviour { public float speed = 0.1f; private bool allowDrag; private OnlineMaps map; private void OnGUI() { GUIStyle style = new GUIStyle(GUI.skin.button); allowDrag = GUI.RepeatButton(new Rect(5, 5, 100, 100), "Drag", style); if (GUI.Button(new Rect(5, 130, 100, 100), "+")) map.zoom++; if (GUI.Button(new Rect(5, 260, 100, 100), "-")) map.zoom--; GUI.Label(new Rect(5, Screen.height - 50, Screen.width - 10, 50), Input.gyro.rotationRate.ToString("F4")); } private void Start() { OnlineMapsControlBase.instance.allowUserControl = false; Input.gyro.enabled = true; map = OnlineMaps.instance; } private void Update() { if (!allowDrag) return; Vector3 rate = Input.gyro.rotationRate; double lng, lat; map.GetPosition(out lng, out lat); double tx, ty; map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx, out ty); tx -= rate.y * speed; ty -= rate.x * speed; map.projection.TileToCoordinates(tx, ty, map.zoom, out lng, out lat); map.SetPosition(lng, lat); } }