# Time based scoring

 0 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; more ▼ asked Apr 22 '12 at 01:15 PM hariprasadh10792 48 ● 8 ● 8 ● 9 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 ``````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. more ▼ answered Apr 22 '12 at 01:33 PM Fabkins 675 ● 15 ● 20 ● 26 I just used the code but it gives me 2 errors! Assets/Scripts/MainScene/ScoreGUI.js(10,14): BCE0044: expecting (, found 'CalclulateScore'. Assets/Scripts/MainScene/ScoreGUI.js(10,29): BCE0044: expecting EOF, found '('.How do I fix them! Apr 22 '12 at 01:41 PM hariprasadh10792 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. Apr 22 '12 at 02:19 PM Kleptomaniac Sorry typo.@Kleptomaniac, 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. Apr 22 '12 at 03:21 PM Fabkins PS corrected typo. I was having a mad moment and mixing JS and C#. Apr 22 '12 at 03:24 PM Fabkins Thanks a lot for that! But when it prints on the screen it even displays Milli-seconds with it, is there a way just to display seconds? Apr 22 '12 at 03:52 PM hariprasadh10792 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 It displays mili-second because u have assigned the score avriable as float. ``````var score : int; ``````now the scoring will in fixed valuewhat you can also do is : ``````var score : int function Start() { score = 0; } function Update() { score = Time.timeSinceLevelLoad; Debug.Log("score"); } `````` more ▼ answered Aug 30 '12 at 08:51 AM getbiks 0 ● 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1968
x573
x351
x274
x34

asked: Apr 22 '12 at 01:15 PM

Seen: 904 times

Last Updated: Aug 30 '12 at 08:51 AM