V
V
Vrtop2019-08-20 10:23:19
Unity
Vrtop, 2019-08-20 10:23:19

How to add magnetometer sensor in unity?

How to add magnetometer sensor in unity

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekseyHunter, 2019-08-20
@Vrtop

Hang the script on the Text object and see the values ​​of the compass axes.

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
public class test : MonoBehaviour {

  public Vector3 xyz; 
  private Text textlabel; 
  // Use this for initialization 
  void Start () { 
    textlabel = gameObject.GetComponent<Text>(); 
    Input.compass.enabled = true; 
  } 
  
  // Update is called once per frame 
  void Update () { 
    xyz = Input.compass.rawVector; 
      textlabel.text = string.Format ("x={0}:y={1}:z={2}:enabled={3}",xyz.x,xyz.y,xyz.z,Input.compass.enabled); 
  } 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question