How to create a Timer [Tutorial][C#] – Unity 3d

43
1



Unity 5 timer
In this video, we learn how to keep track of the time and how to format a timer string, we then proceed to display this string in our Update function and we stop the timer using an external trigger.

►——————————————————-◄
Join the community, keep on learning.

► Come hang out in discord! This is the most efficient way to reach not only the team members but thousands of other developers like you! We love it when you help, showcase or just discuss with each other in discord!

► Learn about unity and game design with this playlist:

► If you enjoy what I do here and would like to support me, pledge any amount on Patreon.

►——————————————————-◄
Stay up to date!

N3K is friendly, laidback community that helps you create video games, and make friends while doing so. Check out our website to learn more, or join us on discord!

► Keep up to date with our plans! Follow the Facebook page

►——————————————————-◄
More content!

Do you need some ideas?
Try out our Unity Training playlist!

►Subway Surfer, mobile game:
►Glide, Mobile game Tutorial:
►Multiplayer Checkers Tutorial:
►2.5D Platformer Tutorial (Noob friendly!):
►Unity Mobile Game (Roller Ball):
►Endless Runner:
►Chess Game:

Nguồn: https://twentyfiveautumn.com/

Xem thêm bài viết khác: https://twentyfiveautumn.com/game/

43 COMMENTS

  1. what if i want to have something bigger then "minutes" becouse when it hits 60 it just restarts.
    can you please help me?

  2. AssetsTimer.cs(18,19): error CS0200: Property or indexer 'Time.time' cannot be assigned to — it is read only
    help plz

  3. Guys, take a look at TimeSpan . The following code displays, minutes, seconds and milliseconds 00:00:000. You can use hh' for hours or only two f's to display two millisecond digits.

    TimeSpan time = TimeSpan.FromSeconds(currentTime);
    timerTMPro.text = time.ToString("mm':'ss':'fff");

    Note: You need to import System for this to work.

  4. any short script if player collide with collider then my finish game meny pop up and every thing stop share the script it will help

  5. the following code gives better result in term of presentation and precision.
    float t = Time.time – starTime;

    string minutes = ((int)t / 60).ToString();

    string seconds = ((int)t % 60).ToString("D2");

    string millisec = ((int)(t * 100f) % 100).ToString("D2");

    timerText.text = minutes + " : " + seconds + " : " + millisec;

    merci pour les tutos et l'effort.

  6. this tutorial is really helpful! however for what im doing, i need some help. im making a game where you have to collect all the balls bouncing around an arena in the shortest amount of time possible. and i need to know how to stop the timer when you collect all the balls. not when you enter a zone.

  7. This is the best lesson! I do not know English, understood everything, and watched the native language was not clear.) (Translated through Google translator)

  8. Check out original developer of this in his new channel
    https://www.youtube.com/channel/UCsaXQNLxeHvwJdDUrICGufA

  9. Is there any way to reset the timer? like, set its value to 0 if it goes over a certain value? Plz help

  10. Just gonna post this here since I just watched your tutorial and perhaps someone else will get momentarily stumped.
    .SendMessage("Finnish"); I thought this was just a worthless string but off course this needs to be the same as your function for stopping the timer in the timer script or else it will send you a "has no reciever" message

  11. The details are so satisfying and awesome !! ..

    By the way, is it possible if i can have your advice in this open source android app I have posted below? I am still a beginner and many things to learn. I hope to get more feedback to improve it!…

    You may search ' pub:Path Ahead ' in Google Play (P & A are case sensitive).

    Thank-you so-so-so-much !!

  12. This is a stopwatch stupid. No hate but still. a timer counts down till it hits 0, but a stopwatch goes up till you stop it. doy

  13. what if your on visual studio ? i had an error at timerText.text at the end

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

    public class Playtime : MonoBehaviour
    {
    public Text Playtimer;
    private float startTime;
    private object timerText;

    void Start () {
    startTime = Time.time;
    }

    // Update is called once per frame
    void Update () {
    float t = Time.time – startTime;

    string minutes = ((int) t / 60).ToString();
    string seconds = (t % 60).ToString("f2");

    timerText.text = minutes + ":" + seconds;
    }
    }

    can someone please help?

  14. I would like that when the car entry into the trigger. The game got finished. Or If the car collision 3 times with the trigger, the game then finished.

    Pls help, how could I do this? :v

LEAVE A REPLY

Please enter your comment!
Please enter your name here