ShowMeaningOfLife.cs 908 Bytes
Newer Older
Rory's avatar
Rory committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShowMeaningOfLife : MonoBehaviour {

	Text TestText;
	float MeaningOfLife; 

	// Use this for initialization
	void Start () {
		TestText = GetComponent<Text>();

		if (Application.platform == RuntimePlatform.Android)
		{
			using (var androidPlugin = new AndroidJavaClass("com.deovolentegames.geocachingunityplugin.GeocachingGamePlugin"))
			{
				using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
				{
					using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
					{
						MeaningOfLife = androidPlugin.CallStatic<float>("GetMeaningOfLife");
					}
				}
			}

			TestText.text = "The Meaning of life is " + MeaningOfLife + ".";
		}
		else
		{
			TestText.text = "Not running on an Android device!";
		}
    }
}