Unity3d 团结不是';不允许使用位置-Windows 10

Unity3d 团结不是';不允许使用位置-Windows 10,unity3d,location,windows-10,location-services,Unity3d,Location,Windows 10,Location Services,我正在Unity 3D游戏中使用定位服务。我正在使用Unity文档中找到的这个(稍微修改过的)脚本,只是为了测试。以下是脚本: using UnityEngine; using System.Collections; public class TestLocationService : MonoBehaviour { IEnumerator Start() { // First, check if user has location service enable

我正在Unity 3D游戏中使用定位服务。我正在使用Unity文档中找到的这个(稍微修改过的)脚本,只是为了测试。以下是脚本:

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();
}
使用UnityEngine;
使用系统集合;
公共类TestLocationService:MonoBehavior
{
IEnumerator Start()
{
//首先,检查用户是否启用了位置服务
如果(!Input.location.isEnabledByUser)
印刷品(“否”);
屈服断裂;
//在查询位置之前启动服务
Input.location.Start();
//等待服务初始化
int maxWait=20;
while(Input.location.status==LocationServiceStatus.Initializing&&maxWait>0)
{
返回新的WaitForSeconds(1);
maxWait--;
}
//服务在20秒内没有初始化
if(maxWait<1)
{
打印(“超时”);
屈服断裂;
}
//连接失败
if(Input.location.status==LocationServiceStatus.Failed)
{
打印(“无法确定设备位置”);
屈服断裂;
}
其他的
{
//已授予访问权限,无法检索位置值
打印(“位置:“+Input.Location.lastData.latitude+”“+Input.Location.lastData.longitude+”“+Input.Location.lastData.altitude+”“+Input.Location.lastData.HorizontalAccurance+”“+Input.Location.lastData.timestamp”);
}
//如果不需要连续查询位置更新,则停止服务
Input.location.Stop();
}
}

当我运行脚本时,它应该打印我的位置。但是,它认为没有启用位置服务(我使用的是Windows 10),只是在停止之前打印“否”。在我的位置设置中,我启用了位置


为什么不允许Unity使用我的位置?

您必须授予Unity使用位置服务的权限。 如果你在发布的屏幕截图上向下滚动,你还必须切换Unity的开关

如果这不起作用,你可能想试着安装一些地理传感器,看看是否有什么不同


基于api输入。location.isEnabledByUser应仅适用于(仅适用于手持设备)

Unity中的location access仅适用于手持设备(即手机和平板电脑)。您不能在计算机上使用它


Unity文档:

Unity没有切换开关。我需要在Unity中启用一些设置吗?你可以试试