Repeatedly creating infinite loops slows down code

So I posted this question earlier, but the mod closed it saying I should write my scripts in c# instead of JavaScript, which is NOT a solution.


So I’ve built a very simple prototype for a day/night system. The scene has a plane that is 8x8 as the ground, 3 little houses I made out of cubes, a tall skinny cube (just there to cast a shadow), and 2 short cubes to represent characters. I also have 2 text renderers set up, one shows the current time (to include seconds) and the other shows the date.

Then I have a handful of scripts that control flow of time and display of date/time.

I noticed that the longer my app runs in play mode, the lower the framerate drops. It starts around 200fps then over a matter of minutes hangs out around 2fps.

When I play with the profiler on, it seems to be the time.js script I have attached to one of the text renderers.

This is it’s code:

#pragma strict

 function Updatetime()
         var today = System.DateTime.Now;
         GetComponent.<TextMesh>().text = today.ToString("hh:mm" + " " + "tt");
         yield WaitForSeconds(0.5f); 
 function Start()
 function Update () {

Now again, this was closed before anyone had the chance to offer advice on the topic.
Is there a better way to write this? Or, does anyone know specifically what might be causing such a frame rate drop over a matter of minutes?

Thanks, community!

Ok, so the problem is that every frame, a script is launched which runs every 0.5 secondes. This means that every frame your computer has to proccess the loop in “Updatetime” again in addition to the ones lying back 0.5 seconds. My suggestion would be remove the “Updatetime()” from the “Update()” function.

I believe what the mod in question said was “You’re misunderstanding how to create a coroutine in unityscript. Carefully read the documentation on this topic and repost if you’re truly stuck.”.

Judging by the fact that you’re posting again, I’m guessing that you’re truly stuck, but perhaps you could share what you’ve tried since last you posted, and why, on every frame of Update(), you’re launching another infinite-running function…?