Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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)]; } }
Comment

PREVIOUS NEXT
Code Example
Csharp :: asp.net unregister client script 
Csharp :: c# create dll runtime 
Csharp :: visual studio debug copy byte[] from watch 
Csharp :: LAST ELEMT OF ARRAY 
Csharp :: 1080 / 7 
Csharp :: and in c# 
Csharp :: unity use of possibly unassigned field struct 
Csharp :: c# interface implementation 
Csharp :: How to use C# to open windows explorer in “select/open file mode 
Csharp :: c# asp.net only displays name of property 
Csharp :: how to detected WindowCloseEvent in other window wpf 
Csharp :: Delete last modification on EntityFramework Core 
Csharp :: EF will not create columns RULE 
Csharp :: c# compare char arrays 
Csharp :: .net core get exe path 
Csharp :: c# initialize array of objects 
Csharp :: player ToJson unity 
Csharp :: how to create new function c# 
Csharp :: windows form toolbox enter key 
Csharp :: c# decimal 
Csharp :: get position of gameobject unity 
Csharp :: unity overlapspherenonalloc 
Csharp :: c# loop example 
Csharp :: freelance 
Csharp :: can lightning strike the same place twice 
Csharp :: getawaiter and no extension method 
Csharp :: git set origin url 
Html :: how to center html element in bootstrap 5 
Html :: favicon html link 
Html :: Javascript getelementbyid hide element 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =