Unity3D 调用GPS位置服务实现代码
来源:互联网 发布:友情岁月演唱会知乎 编辑:程序博客网 时间:2024/04/28 17:10
using UnityEngine;
using System.Collections;
public class GetGPS : MonoBehaviour {
public string gps_info = "";
public int flash_num = 1;
// Use this for initialization
void Start () {
}
void OnGUI () {
GUI.skin.label.fontSize = 28;
GUI.Label(new Rect(20,20,600,48),this.gps_info);
GUI.Label(new Rect(20,50,600,48),this.flash_num.ToString());
GUI.skin.button.fontSize = 50;
if (GUI.Button(new Rect(Screen.width/2-110,200,220,85),"GPS定位"))
{
// 这里需要启动一个协同程序
StartCoroutine(StartGPS());
}
if (GUI.Button(new Rect(Screen.width/2-110,400,220,85),"刷新GPS"))
{
this.gps_info = "N:" + Input.location.lastData.latitude + " E:"+Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
this.flash_num += 1;
}
}
// Input.location = LocationService
// LocationService.lastData = LocationInfo
void StopGPS () {
Input.location.Stop();
}
IEnumerator StartGPS () {
// Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
// LocationService.isEnabledByUser 用户设置里的定位服务是否启用
if (!Input.location.isEnabledByUser) {
this.gps_info = "isEnabledByUser value is:"+Input.location.isEnabledByUser.ToString()+" Please turn on the GPS";
return false;
}
// LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
Input.location.Start(10.0f, 10.0f);
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
// 暂停协同程序的执行(1秒)
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1) {
this.gps_info = "Init GPS service time out";
return false;
}
if (Input.location.status == LocationServiceStatus.Failed) {
this.gps_info = "Unable to determine device location";
return false;
}
else {
this.gps_info = "N:" + Input.location.lastData.latitude + " E:"+Input.location.lastData.longitude;
this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
yield return new WaitForSeconds(100);
}
}
}
Unity3D 钢琴块游戏解析
钢琴块游戏非常的简单,主要是4X4的一个方陈,块从上向下移动,每行四个块有3个白块一个黑块,
操作者点击黑块变为白色,如果有未点击的黑块到达底部后,游戏结束。
实现方法有很多,今天讲解一种最贴近untiy知识点,又非常简单的方法。
知识点:碰撞,重力,触发器,预设
实现方法:
1.制做一个Cube 做成一个prefab(预设)。注:四个块通用这个
在这个Cube上增加一个脚本,用于记录当前块的颜色状态,及点击事件。
为Cube增加刚体及碰撞器,让物体由上向下自由下落。
2. 制做一个行Prefab ,拖动四个Cube的prefab做为子对象。
为父Prefab增加脚本,生成(1-4)的随机值,用于初始化,四个Cube中哪个为黑色块。
3.在摄影机的最底部加入一下触发器。
同时加入脚本,如果下落的物体中有未点击的黑色,那么游戏结束。如果无黑色块,销除整个父Prefab.
4.在父prefab下落的过程中加入一个触发器。
脚本控制生成新的父Prefab及子物体
- Unity3D 调用GPS位置服务实现代码
- 位置服务及GPS定位的调用
- GPS位置服务
- 调用GPS定位服务
- Android 位置服务与GPS实时定位
- GPS跟踪位置变化过程的代码
- unity3d调用Android的java代码实现地图的连接
- android 默认打开位置服务,默认关闭GPS设置
- android位置服务与GPS实时定位工具类
- android 调用系统的位置与安全(GPS)页面
- Android下实现GPS定位服务
- Unity3D调用Android Java代码
- Unity3D调用Android Java代码
- HTML5调用本地相机服务(实现代码)
- 使用USRP和GNU Radio实现GPS位置伪造
- 调用Android位置服务获取当前坐标
- 代码实现开启或关闭GPS
- Unity3d获取GPS 经纬度
- 第三次作业
- 第8章 路由观念与路由器设定
- JAVA程序设计(13.1)---- 循环 数组 应用复习,约瑟夫环问题
- manacher 算法
- 第10周项目1(3)-getchar总结
- Unity3D 调用GPS位置服务实现代码
- java---计算出现次数最大的任意字符
- Struts2 国际化
- 时空上下文视觉跟踪(STC)算法的解读与代码复现
- 成绩转换
- 崩溃恢复和介质恢复的区别
- C#小结
- QCustomPlot实现动态折线图
- 表单乱码问题解决