0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unityのサブスレッドで5msごとに処理

Last updated at Posted at 2021-04-05

Unityのサブスレッドで5msごとに処理
多分こんな感じ

以下を参考にしました。
https://teratail.com/questions/109591

using UnityEngine;
using System.Threading;
using System;

public class UnitySubThreadTimer : MonoBehaviour
{
    Thread thread;
	
	// Start is called before the first frame update
	void Start()
    {
        thread = new Thread(new ThreadStart(SubThread));
        thread.Start();
    }
	void SubThread()
	{
		//Process once every 5ms
		long next = DateTime.Now.Ticks + 50000;
		long now;

		while (true)
		{
			try
			{
				Debug.Log(Time.time);
			}
			catch
			{
			}

			do
			{
				now = DateTime.Now.Ticks;
			} 
			while (now < next);
			next += 50000;
		}
	}

	void Stop()
	{
		thread.Abort();
	}

	void OnApplicationQuit()
	{
		thread.Abort();
	}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?