TimeSince

Tuesday, January 16, 2018

Here's a little utility script for Unity. Since I made it I've used it a few times in my prototype, so thought I'd share.

It's basically a way to get the time since something happened, made to be a member of a class/component. It's so simple that I'm guessing it already exists in a form that I've missed.

using UnityEngine; public struct TimeSince { float time; public static implicit operator float(TimeSince ts) { return Time.time - ts.time; } public static implicit operator TimeSince(float ts) { return new TimeSince { time = Time.time - ts }; } }

It'll act like a float, but it'll change over time.

TimeSince ts; void Start() { ts = 0; } void Update() { if ( ts > 10 ) { DoSomethingAfterTenSeconds(); } }

It's a struct so it doesn't create garbage.

More Rubbish

Your Portfolio Gave Me Diarrhea

Friday, October 1, 2021

Motivation

Friday, September 24, 2021

We got married

Thursday, September 16, 2021

Unity Quiz

Sunday, September 6, 2020

Everything We Watched In Lockdown

Thursday, September 3, 2020

Kitchen Wank

Saturday, January 13, 2018

Prototyping

Thursday, January 11, 2018

Displaying an Avatar

Wednesday, January 10, 2018

Player Name Overlay

Tuesday, January 9, 2018

Tesla Model X

Sunday, September 3, 2017