Version: 2021.2

Gyroscope.rotationRate

切换到手册
public Vector3 rotationRate ;

描述

返回设备陀螺仪测量的旋转速率。

旋转速率以 Vector3 的形式提供, 表示围绕三个轴中的每一个的旋转速度(以弧度/秒为单位)。这是陀螺仪硬件报告的值 - 可以使用 rotationRateUnbiased 属性获取经去“偏差”处理的更精确的测量值。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float shakeSpeed; public AudioClip shakeSound; AudioSource audioSource;

void Start() { audioSource = GetComponent<AudioSource>(); }

void Update() { if (Input.gyro.rotationRate.y > shakeSpeed &amp;&amp; !audioSource.isPlaying) audioSource.PlayOneShot(shakeSound); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961