using System.Collections; using System.Collections.Generic; using UnityEngine; public class Accelerometr : MonoBehaviour { public float smooth = 1.0f; public float tiltAngle = 20.0f; public Canvas canvas; private void Start() { canvas.enabled = false; } void Update() { #if UNITY_EDITOR // Smoothly tilts a transform towards a target rotation. float tiltAroundY = -Input.GetAxis("Horizontal") * tiltAngle; float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle; // Rotate the cube by converting the angles into a quaternion. Quaternion target = Quaternion.Euler(tiltAroundX, tiltAroundY, 0); // Dampen towards the target rotation transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); #else float tiltAroundY = -Input.acceleration.x * tiltAngle; float tiltAroundX = Input.acceleration.y * tiltAngle; Quaternion target = Quaternion.Euler(tiltAroundX, tiltAroundY, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); #endif } }