This question has been asked several times all over the internet, I looked all over, tried many examples but I’m not getting anywhere.
I’m trying to get the variable “convert” the display the time since loaded from the “min_time” variable from another script.
I’m trying to make a timer and put it on screen. The console give me no errors but the result I’m getting is a big fat zero. Why? How do I fix it?
RunStyle.cs
using UnityEngine;
using System.Collections;
public class RunStyle : MonoBehaviour {
// Use this for initialization
//void Start () {
//}
// Update is called once per frame
// Update () {
//}
public GUIStyle Run_Style;
public string Sec;
//public GM_Timer GameMaster;
//public GameObject gameMaster;
public float convert;
void Start () {
}
void Update ()
{
GameObject gamemaster = GameObject.Find("GameMaster");
GM_Timer gm_timer = gamemaster.GetComponent<GM_Timer>();
float convert = gm_timer.min_time;
string Sec = convert.ToString();
}
void OnGUI ()
{
GUI.Label (new Rect (10, 10, 500, 100), ("Time Passed is:" + Sec),Run_Style);
}
}
GM_Timer.cs
using UnityEngine;
using System.Collections;
public class GM_Timer : MonoBehaviour {
// Use this for initialization
public float min_time;
public float sec_time;
void Start () {
}
// Update is called once per frame
void Update () {
min_time = Time.timeSinceLevelLoad;
sec_time = Time.timeSinceLevelLoad;
}
//some functions that didn't work either.
public float Minutes () {
float result = (Mathf.Floor(120 - min_time)/60);
return result;
}
public string Seconds () {
float result = min_time;
string converted = result.ToString();
return converted;
}
}
Inspector image is attached: