2016-08-01 133 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

相关问题