I have found a script to find the GPS location of the user, here’s that code:
using UnityEngine;
using System.Collections;
public class CurrentLocation : MonoBehaviour
{
public static string CurrLoc { get; internal set; }
IEnumerator Start()
{
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
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
string CurrLoc = Input.location.lastData.latitude + " " + Input.location.lastData.longitude;
}
// Stop service if there is no need to query location updates continuously
// Input.location.Stop();
// Line above commented out because it needs to constantly update.
}
}
I want to call CurrLoc from CurrentLocation.cs (the code above) into another Menu.cs file into a function, here’s that code:
public void SmsButton()
{
string Content = "sms:" + ContNum + "?body=" + WWW.UnEscapeURL(CurrentLocation.CurrLoc);
Application.OpenURL(Content);
}
Basically what this will do is actively get the GPS location of the user and the button that calls “SmsButton()” will text the location to a specified contact number. While this does not give any complier errors it doesn’t return any values. How can I accurately call the CurrLoc variable from the CurrentLocation.cs?