Unity hand-made timer doesnt work?

When character goes the area, the timer starts just once time but when character goes second time it always stop in zero and not working again

public bool collectable_item;
public float seconds;

private void CharGoing ( string destination )
{
    if (transform.position == GameObject.Find(destination).transform.position) 
        collectable_item = true;
    if (transform.position == GameObject.Find("storagearea").transform.position)
        collectable_item = false;
}

public void CharWent ( string destination , float secondsTillJobdone )
{
    chargoing( destination );
    if( collectable_item==true )
    {
        //checkTimerProproperties = true;
        seconds += Time.deltatime;
        if( seconds>secondsTillJobdone )
        {
            transform.position = Vector2.MoveTowards(transform.position, GameObject.Find("storagearea").transform.position, 1.2f * Time.deltaTime);
            seconds = 0;
        }
    }
    else
    {
            transform.position = Vector2.MoveTowards(transform.position, GameObject.Find(destination).transform.position, 1.2f * Time.deltaTime);
    }        
}
  • Don’t compare object positions with == but calculate distance between them

and test for less than threshold value:

float dist = Vector3.Distance( transform.position , destination.transform.position );
if( dist < 0.1f ) 
    collectable_item = true;

_

  • Using GameObject.Find is unreliable and slow (the same applies to tags), try to replace it with

direct references to GameObjects.

[SerializableField] GameObject _destination = null;