Jump to content
Unity Insider Forum

Recommended Posts

die Skripte der anderen Szenen sollten doch alle einen direkten Zugriff auf die Timer-Variable in der der Timer-Klasse haben. Jedoch möchte ich in der 'Timer-Klasse' auch eine Update()-funktion haben. Darum sollte sie eben von MonoBehaviour ableiten...

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class mytimer_class : MonoBehaviour {
    public Button btn1, btn2;
    bool timerActive = false;
    float cntdnw = 1.0f;
    public Text disvar;

    // Use this for initialization
    void Start () {
        btn1 = GameObject.Find("start_button").GetComponent<Button>();
        btn2 = GameObject.Find("stop_button").GetComponent<Button>();

    public void starttimer()
        string timer_stop = PlayerPrefs.GetString("stopped_time");
        // dt = new DateTime(2021, 01, 01).AddDays(Convert.ToDouble(timer_stop));
        btn2.interactable = true;
        btn1.enabled = true;
        timerActive = true;

    public void stopptimer()
        btn2.enabled = true;
        // startButton.enabled = false;
        timerActive = false;
        btn1.interactable = true;

    // Update is called once per frame
    void Update () {
        if (timerActive == true)
            cntdnw += Time.deltaTime;

            double b = System.Math.Round(cntdnw, 2);
            string dateTimeString = System.String.Format("{0:yyyy-MM-dd-hh}", b);

            var time = new DateTime(Convert.ToInt64(b));
            DateTime dt = new DateTime(2021, 01, 01).AddDays(b);

            disvar.text = dt.ToShortDateString();
            //DateTime dt = DateTime.FromOADate(b);
            // disvar.text = dt.ToShortDateString();




Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...