2012-02-27 69 views
3

我正在开发面向Android项目的Unity3d。从统一使用文档:Unity3d Input.location from code

http://unity3d.com/support/documentation/ScriptReference/Input-location.html

我应该能够使用Input.location以访问GPS位置数据。但是,我得到一个错误,基本上告诉我Input.location不是Unity的一部分。

资产/脚本/ Prototype1.js(27,29):BCE0019: '位置' 不是 'UnityEngine.Input' 的 构件。

我检查了更新,它告诉我系统已完全更新。我正在运行版本3.4.2f3

文档是否过期?是否有对LocationService的不同参考?我如何获取位置数据?

+0

作为任何人谁发现这个问题的说明。始终从Unity3d中打开Unity3d脚本引用。它在“帮助”>“脚本参考”之下截至目前,Unity的网站显示了3.5的文档,但3.5不是当前的稳定版本。例如,iPhoneSettings未列在Unity托管参考中,但列在本地安装的参考中。 – Chris 2012-03-01 06:14:53

回答

1

我发现文档的旧代码,总部设在iPhoneSettings。这是我现在使用的代码,它不完整(不响应超时位置服务和其他全面行为),但演示代码。

function Start() { 
    locationStatus = LocationServiceStatus.Stopped; 

    StartCoroutine(startLocationService()); 
} 

function Update() { 
    if(locationStatus == LocationServiceStatus.Running) 
    { 
     /* 
     lat = Input.location.latitude; 
     lon = Input.location.longitude; 
     alt = Input.location.altitude; 
     */ 

     lat = iPhoneInput.lastLocation.latitude; 
     lon = iPhoneInput.lastLocation.longitude; 
     alt = iPhoneInput.lastLocation.altitude; 
    } 
} 

function startLocationService() 
{ 
    //Input.location.Start(accuracy, distance); 
    iPhoneSettings.StartLocationServiceUpdates(accuracy, distance); 

    //while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { 
    while(iPhoneSettings.locationServiceStatus == LocationServiceStatus.Initializing && maxWait > 0) 
    { 
     yield WaitForSeconds(1); 
     maxWait--; 
    } 

    //locationStatus = Input.location.status; 
    locationStatus = iPhoneSettings.locationServiceStatus; 
} 
2

unity3d.com上的文件包含最新版本Unity3D 3.5的文档。如果您查看本地文件系统中的文档,您将找不到Input.location。看起来他们已经改变了Unity3D 3.5的界面。

我没有使用过GPS直到现在,也许这线程和所提供的链接可以扔在这一些轻:

How to import GPS location coordinates from Android device?

+1

该页面上的最后一条评论是让我感到满意的地方。 – Chris 2012-03-01 06:12:23

相关问题