About multiple Thread

My Code:

using UnityEngine;

using System;

using System.Collections;

using System.Threading;

public class MyThread

{

public int count;

string thrdName;

public MyThread(string nam)
{
     count = 0;

  thrdName = nam;
}
public void run()
{

 ***Debug.Log("start run a thread" + Time.time);***

}

}

public class NewBehaviourScript : MonoBehaviour {

void Start () {

  Debug.Log("start main"+Time.time);

  MyThread mt = new MyThread("My Thread");

  Thread newThrd = new Thread(new ThreadStart(mt.run));

  newThrd.Start();

}

// Update is called once per frame

void Update () {

     Debug.Log(Time.time);

}

}

i think it can work,but in function run(),this line:Debug.Log("start run a thread" + Time.time);" can not always. The warning is "UnityEngine.Time:get_time(),MyThread:run() (at Assets\script\NewBehaviourScript.cs:20)".

who can show me the right way to do something in the new thread.i know it's the problem of multiple thread's. thank you.

Unity is not Thread-safe. This means, while no one can stop you from starting your own Threads, you can't access any internal Unity stuff safely from your Threads. I guess Time.time is one of the things you can't access safely.

So if you want to use Threading anyway it normally works to make a copy of the data that your Thread should work on do your thing with it and afterwards copy the data back to unity. Also in most cases you will be fine using a coroutine rather than a Thread.