add unity multithreading project
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Animations
|
||||
{
|
||||
public class ThreadAnimation : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
// CAUTION: you can not access Unity Objects from a thread which is not the main thread, e.g. transforms
|
||||
// WARNING: never ever put the main thread to sleep
|
||||
// Thread thread = new Thread(() =>
|
||||
// {
|
||||
float time = 0.0f;
|
||||
|
||||
// move
|
||||
while (time < 1.0f)
|
||||
{
|
||||
transform.position = Vector3.Lerp(Vector3.zero, Vector3.forward * 5.0f, time);
|
||||
Thread.Sleep(100);
|
||||
time += 0.1f;
|
||||
}
|
||||
|
||||
// scale
|
||||
time = 0.0f;
|
||||
while (time < 1.0f)
|
||||
{
|
||||
transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2.0f, time);
|
||||
Thread.Sleep(100);
|
||||
time += 0.1f;
|
||||
}
|
||||
// });
|
||||
// thread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user