我在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),并在停止之前打印“否”。在我的位置设置中,我已启用位置。
为什么不团结允许使用我的位置?
没有团结切换开关。在Unity中需要启用一些设置吗? –
你可以试试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