PhotonNetwork.time

Options
Hello im using the PhotonNetwork.time to sync the time for all players in my room but my problem is that i want make it to minutes and seconds and the seconds should have 2 digits.

but currently the PhotonNetwork.time uses double as digit.
how can i show only 2 digits of the seconds like Time.deltatime

Comments

  • unitylearner
    Options
    This will help you

    ///
    /// This returns a formatted string showing the time
    ///
    /// The time that should be formatted
    ///
    public void SetTimeLeftString (double timePassed)
    {
    double timeLeft = GameSetup.TimeLimit - timePassed;
    int minutesLeft = Mathf.FloorToInt ((float)timeLeft / 60);
    int secondsLeft = Mathf.FloorToInt ((float)timeLeft) % 60;
    minutesLeft = (minutesLeft >= 0 ? minutesLeft : 0);
    secondsLeft = (secondsLeft >= 0 ? secondsLeft : 0);
    TimeLeftString = minutesLeft.ToString () + ":" + secondsLeft.ToString ("00");
    }
  • how GameSetup.TimeLimit - timePassed ?
  • Hi,

    I would suggest you use c# own timespan system and work with it, it will give you the whole set of api to query time.

    https://www.dotnetperls.com/timespan
    https://msdn.microsoft.com/en-us/library/system.timespan.fromseconds(v=vs.110).aspx

    Then you can parse as xx.ToString ("00") from timespan values.

    Bye,

    Jean