Version: 2020.1
LanguageEnglish
  • C#

Gyroscope.gravity

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public Vector3 gravity;

Description

Returns the gravity acceleration vector expressed in the device's reference frame.

using UnityEngine;

public class Example : MonoBehaviour { float movementScale;

void Update() { // A "spirit level" - the dot product of the gravity and the Y axis (ie, Vector3.up) // is a measure of how far the device is from level on that axis (it will be zero // if the device is perfectly level). This value can be used to position an object // to act as the "bubble". Vector3 pos = transform.position; pos.y = Vector3.Dot(Input.gyro.gravity, Vector3.up) * movementScale; transform.position = pos; } }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答