• 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 /
avatar image
0
Question by kapuscianyglab · Jul 28, 2013 at 08:17 PM · timer

"How to make and display in GUI timer"

I have similar problem to http://answers.unity3d.com/questions/45455/thow-to-start-a-timer-display-as-gui.html in my racer game. I'm looking step by step tutorial "How to make and display in GUI timer". I have 2 line: starting line and finisz line. If player cross starting line - time start. But if player cross finish line - time stop.

I tried add script from above link to starting object and script doesn't work.

Comment
Add comment · Show 1
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 Kawaburd · Jul 28, 2013 at 09:02 PM 0
Share

What's your code look like, and what part isn't working? We need more info - could be timer isn't working period, or isn't seeing the starting line, or even IS working but not displaying right. Are you getting Unity errors, or just gameplay bugs?

This question doesn't contain enough information for us to even give you an educated guess of an answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kapuscianyglab · Jul 28, 2013 at 09:30 PM

My car's inspector look like:

alt text

My cube's inspector look like:

alt text

My code for timer attach to cube:

 using UnityEngine;
 using System.Collections;
  
 public class Timer: MonoBehaviour 
 {
   private float startTime;
   private float elapsedTime;
  
   void Awake(){
  startTime = 0;      
   }
  
   void Update () {
  
   if (startTime > 0)
     {
        elapsedTime = Time.time - startTime;
     }
   }
 
   void OnTriggerEnter(){
     startTime = Time.time;
   }
  
 void OnTriggerExit(){
     startTime = 0;
   }
  
   void OnGUI(){
  GUI.Label(new Rect(300, 100, 100, 20), (elapsedTime.ToString()));
   }
 }

If I go near to cube - timer doesn't count time and display 0.


inspector_car.png (15.0 kB)
inspector_cube.png (15.8 kB)
Comment
Add comment · Show 4 · 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 nixcs2512 · Jul 28, 2013 at 09:48 PM 1
Share

You use OnTrigger but forgot to check Is Trigger to your cube - timer.And your car got Rigidbody or CharacterController yet?

avatar image kapuscianyglab · Jul 28, 2013 at 09:54 PM 0
Share

I didnn't use rigidbody. Controller use from "EasyTouch" from AssetStore.

avatar image nixcs2512 · Jul 28, 2013 at 10:14 PM 1
Share

so try to check the Is Trigger tick box in Cube Inspector,hope it works :)

avatar image kapuscianyglab · Jul 29, 2013 at 02:14 PM 0
Share

Thanks. $$anonymous$$y script work. But If I go near to cube - time start, but if I go away from cube - time stop. I want script which measure time through all race, when car start.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Countdown Timer location 1 Answer

My timer freezes everytime I leave the scene and come back. 1 Answer

Delay between throwing/firing object 1 Answer

How can I add a timer that will start when the game starts and stop when the game ends and records it? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges