Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by dandelo99 · May 03, 2016 at 08:30 PM · timetimertimescaletimer-script

how can i take time value from timer (Asked again clearly)

I have timer and checkpoints in my game i want to write down moments when player passes this check points i can handle with text things it is easy but i cant write down time when timer still working is it possible i want to give example now time starts and you reach first checkpoint at 00:11:12 and second 00:22:44 third 00:35:32 it will be shown like this

  1. Current Time : 00:35:32 (same with third checpoint 1.Check : 00:11:12 2.Check : 00:22:44 3.Check : 00:35:32

There is part of my timer Script corresponding i search everywhere but couldn't find thanks a lot

      if(SceneTestMap.GetComponent<SceneTest_Map>().checkPoint==1)
      {
     
         checkPoint.text = TimeToString(?????);
      }

this is the whole script

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
  public class Timer : MonoBehaviour {
  
  public Text timerText;
  private float startTime;
  public GameObject SceneTestMap;
  public Text Hedef_74text;
  
      bool keepTiming;
      float timer;
  
      void Start () {
          StartTimer();
      }
  
      void Update () {
          if(SceneTestMap.GetComponent<SceneTest_Map>().IsRaceFinished == true){
              Debug.Log("Timer stopped at " + TimeToString(StopTimer()));
          }
  
          if(keepTiming){
              UpdateTime();
          }
          if(SceneTestMap.GetComponent<SceneTest_Map>().checkPoint==1)
          {
         
             checkPoint.text = TimeToString(?????);
          }
      }
  
      void UpdateTime(){
          timer = Time.time - startTime;
          timerText.text = TimeToString(timer);
      }
  
      float StopTimer(){
          keepTiming = false;
          return timer;
      }
  
      void ResumeTimer(){
          keepTiming = true;
          startTime = Time.time-timer;
      }
  
      void StartTimer(){
          keepTiming = true;
          startTime = Time.time;
      }
  
      string TimeToString(float t){
          string minutes = ((int) t / 60).ToString();
          string seconds = (t % 60 ).ToString("f2");
          return minutes + ":" + seconds;
      }
  }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 03, 2016 at 08:31 PM

How about:

 text = TimeSpan.FromSeconds(timeValue).ToString();
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dandelo99 · May 03, 2016 at 08:36 PM 0
Share

I am taking error about TimeSpan thing not worked Assets/Scripts/Timer.cs(31,45): error CS0103: The name `TimeSpan' does not exist in the current context

avatar image FortisVenaliter dandelo99 · May 04, 2016 at 05:57 PM 0
Share

https://msdn.microsoft.com/en-us/library/t8zbaa6f.aspx

avatar image dandelo99 · May 04, 2016 at 06:31 PM 0
Share

actually it is not fixing my problem i couldnt figure out i think it was simple like timer-Time.deltaTime or something like that to stop time just writen on checkpoint text

avatar image
0

Answer by dandelo99 · May 04, 2016 at 05:52 PM

(Is it possible otherwise i will try something else)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

40 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can change the text in UI text component each 5 seconds after start timer 1 Answer

Farming game Time management 0 Answers

Load scene after time 1 Answer

How is it possible to verify values and is they are correct activate objects ? 0 Answers

How to make an App that only works for a week? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges