• Unity3D 调用GPS位置服务实现代码


    欢迎来到unity学习unity培训、unity企业培训教育专区,这里有很多U3D资源U3D培训视频U3D教程U3D常见问题U3D项目源码,我们致力于打造业内unity3d培训、学习第一品牌。

     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及子物体

    更多精彩请点击 http://www.gopedu.com/

  • 相关阅读:
    3、选择排序(最小值/最大值)
    2、冒泡排序
    1、快速排序
    Stream操作
    1. 两数之和
    Mysql修改字段类型修改
    获取节假日
    mysql 前缀 + 编号 补0
    一口气说出 6种@Transactional注解的失效场景
    Activiti最全入门教程(基于Eclipse插件开发)
  • 原文地址:https://www.cnblogs.com/Unity3Dqishituan/p/4072212.html
Copyright © 2020-2023  润新知