RakeshChatra
RakeshChatra

Reputation: 105

How to set lapTimer in multiplayer games in unity3d?

As I'm new to the coding and unity3d I'm finding tough to set the lap timer for my racing game which is the multiplayer game.

Upvotes: 1

Views: 877

Answers (1)

Vincent P
Vincent P

Reputation: 426

Well in terms of just code.

Time.time

Will give you the time (duh)

So you'd do something like the following

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

function OnGUI () {
   var currentLap = Time.time - startTime;
}

currentLap is the current time since the script started. So you could run the code in the "Awake()" method when the race starts. Then on screen display what the current lap time is.

Found a nice example from the Unity Developer Network that might be exactly what your looking for here

Upvotes: 1

Related Questions