Horje
compass direction mobile unity Code Example
compass direction mobile unity
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using System; public class CompassBehaviour : MonoBehaviour { public TextMeshPro headingText; private bool startTracking = false; void Start() { Input.compass.enabled = true; Input.location.Start(); StartCoroutine(InitializeCompass()); } void Update() { if (startTracking) { transform.rotation = Quaternion.Euler(0, Input.compass.trueHeading, 0); headingText.text = ((int)Input.compass.trueHeading).ToString() + "° " + DegreesToCardinalDetailed(Input.compass.trueHeading); } } IEnumerator InitializeCompass() { yield return new WaitForSeconds(1f); startTracking |= Input.compass.enabled; } private static string DegreesToCardinalDetailed(double degrees) { string[] caridnals = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N" }; return caridnals[(int)Math.Round(((double)degrees * 10 % 3600) / 225)]; } }
Source: medium.com




Csharp

Related
how to pass value to anothe form c# winform Code Example how to pass value to anothe form c# winform Code Example
verifyusertokenasync password reset token Code Example verifyusertokenasync password reset token Code Example
c# multipthreading Code Example c# multipthreading Code Example
player movement script unity Code Example player movement script unity Code Example
asp.net issue Code Example asp.net issue Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12