unity 13章 多线程技术与网络开发
13.1.1开启线程
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Thread thread = new Thread(run);
thread.Start();
}
// Update is called once per frame
void Update()
{
}
void run()
{
Debug.Log("开启线程");
}
}
13.1.2加锁(同一时刻只能被一个线程访问或者修改)
获取锁才能操作数据,操作数据后释放数据
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class NewBehaviourScript : MonoBehaviour
{
public static Object o = new Object();
public int n = 0;
void Start()
{
Thread thre