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
1
Question by hariprasadh10792 · Apr 22, 2012 at 01:15 PM · iostimetimerscoretime.time

Time based scoring

Hello I am working on a game, can anyone tell me how to calculate the score based on seconds? For instance if the player plays for 10 seconds the score will be 10; 1 second = 1 point;

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
3
Best Answer

Answer by Fabkins · Apr 22, 2012 at 01:33 PM

 var startTime: float;

 function GameStarts()
 {
    startTime=Time.time;
 }

 function CalculateScore(): int 
 {
    return ( Time.time - startTime);
 }


Because time is granular , if you wanted to do you could multiple the result by 10 and have a score that has fractions of a second.

Comment
Add comment · Show 6 · 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 hariprasadh10792 · Apr 22, 2012 at 01:41 PM 0
Share

I just used the code but it gives me 2 errors! Assets/Scripts/$$anonymous$$ainScene/ScoreGUI.js(10,14): BCE0044: expecting (, found 'CalclulateScore'. Assets/Scripts/$$anonymous$$ainScene/ScoreGUI.js(10,29): BCE0044: expecting EOF, found '('.

How do I fix them!

avatar image Kleptomaniac · Apr 22, 2012 at 02:19 PM 0
Share

I'm not really that sure what @Fabkins is doing here ... for one, he seems to have mixed a bit of C# with JS! You could either calculate the score at the end of a playing session by calling this function:

 function CalculateScore () : int {
     return Time.time;
 }

or you could increment as you are going if you want like so:

 var score : int;
 
 function Update () {
     score = Time.time;
 }

Pretty darn simple.

avatar image Fabkins · Apr 22, 2012 at 03:21 PM 0
Share

Sorry typo.

@$$anonymous$$leptomaniac, no you cant use Time.time on its own as its the time since the program started not the time since the game started.

So, typos asside, my code stands.

avatar image Fabkins · Apr 22, 2012 at 03:24 PM 0
Share

PS corrected typo. I was having a mad moment and mixing JS and C#.

avatar image hariprasadh10792 · Apr 22, 2012 at 03:52 PM 0
Share

Thanks a lot for that! But when it prints on the screen it even displays $$anonymous$$illi-seconds with it, is there a way just to display seconds?

Show more comments
avatar image
1

Answer by getbiks · Aug 30, 2012 at 08:51 AM

It displays mili-second because u have assigned the score avriable as float.

 var score : int;

now the scoring will in fixed value

what you can also do is :

 var score : int
 
 function Start()
 {
    score = 0;
 }
 
 function Update()
 {
    score = Time.timeSinceLevelLoad;
    Debug.Log("score");
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Pause Time.time? 1 Answer

Help with time.time when new scene starts. 1 Answer

Changing light intensity over time via mathf.lerp 2 Answers

Why Won't This Message Log Into My Console? 1 Answer

Time.deltaTime not running in background (for local notification) 2 Answers


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