123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Linq;
- public class Compass : MonoBehaviour
- {
- [SerializeField] Text text;
- [SerializeField] Text text1;
- [SerializeField] Text text2;
- [SerializeField] Text text3;
- [SerializeField] Image compass;
- [SerializeField] Transform scene;
- [SerializeField] Text sceneText;
- public LineRenderer X;
- public LineRenderer Z;
- List<float> list_rot;
- bool state;
- float dushu = 0;
- float tempdushu = 0;
-
-
- void Start()
- {
- list_rot = new List<float>();
- Input.compass.enabled = true;
- showLine();
- state = true;
- }
-
-
- void OnGUI()
- {
-
-
-
-
-
-
- }
-
-
- void FixedUpdate()
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (list_rot.Count < 40)
- {
- list_rot.Add(Input.compass.trueHeading);
- }
- else
- if (API_SVR.GetHead() != null && state)
- {
- state = false;
- dushu = list_rot.Average();
-
- scene.eulerAngles = new Vector3(0, 355f - dushu, 0);
- }
-
-
-
-
-
-
-
- text.text = scene.eulerAngles.y.ToString();
- showLine();
- }
- void showLine()
- {
- X.positionCount = 2;
- X.SetPosition(0, transform.position + new Vector3(10, -1, 0));
- X.SetPosition(1, transform.position - new Vector3(10, 1, 0));
- Z.positionCount = 2;
- Z.SetPosition(0, transform.position + new Vector3(0, -1, 10));
- Z.SetPosition(1, transform.position - new Vector3(0, 1, 10));
- }
- }
|