Search Unity

Feedback Quick question.

Discussion in 'Scripting' started by Alnos, Jun 13, 2021.

  1. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    110
    So I saw a video on youtube on how to make a timer slider and it work as intended althoug the video put everything inside Update() and I was wondering, should I put the float time variable inside fix update and multiply it by Time.deltatime instead?

    here's the script:
    Code (CSharp):
    1. float time = attackTime - Time.time;
    2.  
    3.         int minutes = Mathf.FloorToInt(time / 60);
    4.         int second = Mathf.FloorToInt(time - minutes * 60f);
    5.  
    6.         if (time <= 0)
    7.         {
    8.             stopTimer = true;
    9.         }
    10.  
    11.         if(stopTimer == false)
    12.         {
    13.             attackSlider.value = time;
    14.         }
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    FixedUpdate should mainly be used for physics operations, like moving a Rigidbody.

    Update is fine.
     
  3. Alnos

    Alnos

    Joined:
    Aug 20, 2019
    Posts:
    110
    ok ok I know for physic, it's caus not everyone have the same framerate. I touhg it would have influenced time also. thanks mate. :)