Unity3d calling the GPS location service implementation code

Source: Internet
Author: User

Welcome to Unity Learning ,Unity Training ,Unity Enterprise Training and education, where there are many u3d resources , u3d Training Videos ,u3d Tutorials ,u3d FAQs ,u3d project source code , we are committed to building the industry Unity3d Training, learning the first brand.

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 positioning"))
{
You need to start a synergistic program here.
Startcoroutine (Startgps ());
}
if (GUI. button (new Rect (screen.width/2-110,400,220,85), "Refresh 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 used to access the device's location properties (handheld device), static locationservice position
Locationservice.isenabledbyuser whether the location service is enabled in the user settings
if (! Input.location.isEnabledByUser) {
This.gps_info = "Isenabledbyuser value is:" +input.location.isenabledbyuser.tostring () + "Please turn on the GPS";
return false;
}

Locationservice.start () Start update of location service, the last location coordinates will be used
Input.location.Start (10.0f, 10.0f);

int maxwait = 20;
while (Input.location.status = = locationservicestatus.initializing && maxwait > 0) {
Pausing the execution of a synergistic program (1 seconds)
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 Piano Block Game analysis

Piano Block game is very simple, mainly 4x4 a square Chen, block from the top down, each line four blocks have 3 white blocks a black block,
The operator clicks the Black block to white, and if there is a black block that has not been clicked to reach the bottom, the game ends.
There are many ways to achieve this, and today is a very simple way to get close to untiy knowledge.
Knowledge points: Collisions, gravity, triggers, presets

Implementation method:
1. Make a cube into a prefab (preset). Note: Four blocks Universal this
Add a script to the cube to record the current block's color status and click events.
Adds a rigid body and collider to the cube, allowing the object to fall freely from top to bottom.
2. Make a line prefab, drag four cube prefab as sub-object.
Adds a script to the parent prefab, generating a random value (1-4) for initialization, which is a black block in four cubes.
3. Add the trigger at the bottom of the camera.
Also add a script, if the falling object has not clicked Black, then the game is over. If there is no black block, the pin is in addition to the entire parent prefab.
4. Add a trigger to the drop of the parent prefab.
Script control to generate new parent prefab and sub-objects


For more highlights, please click http://www.gopedu.com/


Unity3d calling the GPS location service implementation code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.