SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GPS : MonoBehaviour
  5. {
  6. public static GPS Instance { set; get; }
  7. public float latitude; //위도
  8. public float longitude; //경도
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. Instance = this;
  13. DontDestroyOnLoad(gameObject);
  14. StartCoroutine(StartLocationService());
  15. }
  16. private IEnumerator StartLocationService()
  17. {
  18. if (!Input.location.isEnabledByUser)
  19. {
  20. Debug.Log("GPS없다");
  21. yield break;
  22. }
  23. Input.location.Start();
  24. int maxWait = 20;
  25. while(Input.location.status==LocationServiceStatus.Initializing && maxWait > 0)
  26. {
  27. yield return new WaitForSeconds(1);
  28. maxWait--;
  29. }
  30. if(maxWait <= 0)
  31. {
  32. Debug.Log("없음");
  33. yield break;
  34. }
  35. if(Input.location.status == LocationServiceStatus.Failed)
  36. {
  37. Debug.Log("Unable to determin device location");
  38. yield break;
  39. }
  40. latitude = Input.location.lastData.latitude;
  41. longitude = Input.location.lastData.longitude;
  42. yield break;
  43. }
  44. // Update is called once per frame
  45. }