little help. thank you in advance.

hi guys, building a small text based game,

so this code is designed to take out “secondd” as an int from another code and display it as text counting down. eg. 13…12…11…1…0.

what is actually happening is that the value freezes at the initial sourced value eg. 13 and doesn decrease from there because of the updating.

Any solutions?

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

public class Timeleft : MonoBehaviour {

    public GameObject Posone;
    public Posone timers;
    public float secondd = 0;
    public UnityEngine.UI.Text timer;
    public int minus;
    public int occu;




    // Use this for initialization
    void Update ()
     {    timers = GameObject.FindGameObjectWithTag("p1").GetComponent<Posone>();
         occu = timers.psonefull;

        if(occu == 1){
        timers = GameObject.FindGameObjectWithTag("p1").GetComponent<Posone>();
        secondd = timers.ctp1;
        secondd -= Time.deltaTime;
       
        timer.text = "Time Left:  " + secondd;
        }
        else{
            timer.text = "Cure";
                    }
        //Debug.Log(secondd);
   
           
           
            }
       
       
       
    }

With your current implementation, you should define “secondd” somewhere else like start or a public function called elsewhere.

I would recommend learning to use coroutines as a more long term solution

Well, that update is a little screwy. But whatever timers.ctp1 is, if that value never changes, you’re constantly setting secondd equal to it, which means it will never count down.