2016-08-01 42 views
0

我在Unity 3D遊戲中使用位置服務。我正在使用我在Unity文檔中找到的這個(稍作修改)的腳本,僅用於測試目的。下面是該腳本:Unity不允許使用位置 - Windows 10

using UnityEngine; 
using System.Collections; 

public class TestLocationService : MonoBehaviour 
{ 
    IEnumerator Start() 
    { 
     // First, check if user has location service enabled 
     if (!Input.location.isEnabledByUser) 
      print("no"); 
      yield break; 

      // Start service before querying location 
      Input.location.Start(); 

      // Wait until service initializes 
      int maxWait = 20; 
     while (Input.location.status == LocationServiceStatus.Initializing  && maxWait > 0) 
    { 
     yield return new WaitForSeconds(1); 
     maxWait--; 
    } 

    // Service didn't initialize in 20 seconds 
    if (maxWait < 1) 
    { 
     print("Timed out"); 
     yield break; 
    } 

    // Connection has failed 
    if (Input.location.status == LocationServiceStatus.Failed) 
    { 
     print("Unable to determine device location"); 
     yield break; 
    } 
    else 
    { 
     // Access granted and location value could be retrieved 
     print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp); 
    } 

    // Stop service if there is no need to query location updates continuously 
    Input.location.Stop(); 
} 

}

當我運行該腳本,它應該打印我的位置。但是,它認爲位置服務未啓用(我正在使用Windows 10),並在停止之前打印「否」。在我的位置設置中,我已啓用位置。

enter image description here

爲什麼不團結允許使用我的位置?

回答

0

您必須給Unity提供使用位置服務的權限。 如果您向下滾動發佈的屏幕截圖,則還必須切換Unity的開關。

如果這不起作用,您可能需要嘗試安裝某種地理傳感器,看看它是否有所作爲。基於http://answers.unity3d.com/questions/1219218/windows-10-using-location-with-unity-through-pc-no.html的API Input.location.isEnabledByUser

應該工作只爲(僅適用於手持設備)在Unity

+0

沒有團結切換開關。在Unity中需要啓用一些設置嗎? –

+0

你可以試試http://www.tenforums.com/attachments/drivers-hardware/50767d1438836176t-find-my-device-wifi-feature-set-up-page-says-off-28806d1438836176-location-service-turn-關 - 窗口10 location_on_for_device-1.png – Aleks

相關問題