Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Hansolo776 · Jan 31, 2012 at 06:09 PM · timerplatformstartstop

Timer that stops at the end of the game

I am making a platform game but i want to make a timer that counts the time thil you hit a cube at the end, if you hit the cube the time stops.

how can i make this.

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 fafase · Jan 31, 2012 at 06:59 PM 0
Share

Check collision between the cube and the player and if collision there is, then stop the clock.

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by ByteSheep · Jan 31, 2012 at 09:04 PM

You can use Time.deltaTime to add to a float variable to create a timer and then simply stop adding to it as soon as you collide with the cube:

 var Timer : float = 0;
 var IncreaseTime : boolean = true;
 
 function Update () {
 
   if(IncreaseTime == true)
   {
   Timer += Time.deltaTime;
   }
 }
 
 function OnCollisionEnter (Col : Collision) {
 
   if(Col.gameObject.name == "Cube")
   {
   IncreaseTime = false;
   }
 }


Make sure that your Cube is name "Cube" in your hierarchy view or alternatively change Col.gameObject.name == "Cube" to whatever the name of the cube is.. You can also use tags. Hope this was useful :)

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
avatar image
1

Answer by kaimelar · Jan 31, 2012 at 07:52 PM

Time.timeScale = 0; => This function will stop Time.

Comment
Add comment · Show 1 · 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 Hansolo776 · Jan 31, 2012 at 07:55 PM 0
Share

and how can i make the timer?

avatar image
0

Answer by Posly · Jan 31, 2012 at 09:06 PM

Try this out:

var timer : int = 0;
var hitCube : boolean = false;
function Update () {
//check's if the player hit the cube, if not it counts
if(hitCube = false)
{
timer ++
}
}
//check's if the player hit the cube
function OnTriggerEnter(hit : Collider)
{
if(hit.GameObject.Tag == "Finish Cube")
{
hitCube = true;
}
}
That should work, just make sure to tag the cube as Finish Cube.
Comment
Add comment · Show 1 · 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 ByteSheep · Jan 31, 2012 at 09:12 PM 0
Share

Not hundred percent sure if that code is going to make the timer go +1 every second since you're adding 1 to the timer variable each frame.. That will probably make the timer go a bit quick and the value can vary depending on the computers frame rate :)

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

8 People are following this question.

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

Related Questions

How to stop a timer with GUI button? 1 Answer

Audio after Audio Loop 1 Answer

Race timer needs to stop on trigger. Help 1 Answer

Explosive like in COD 4? 1 Answer

Timer activates script 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