Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions End of the Line 2/Assets/LamdaThreading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using UnityEngine;
using System.Collections;
using System.Threading;
using System.Diagnostics;

public class LamdaThreading : MonoBehaviour {

Thread moveThread;
Thread changeDirection;
bool updated = false;
bool running = true;
Vector3 positionDuplicate;
Vector3 threadReturn;
Vector3 destination;

// Use this for initialization
void Start ()
{
float timeElapsed;
Stopwatch timer;
moveThread = new Thread(() =>
{
timer = new Stopwatch();
while(running)
{
if(updated)
{
timeElapsed = timer.Elapsed.Milliseconds / 1000f;
threadReturn = Vector3.Lerp(positionDuplicate, destination, timeElapsed);
timer = new Stopwatch();
}
}
});
changeDirection = new Thread(() =>
{
int timeCount = 25;
int moveCount = 0;
while (running)
{
if (timeCount == 25)
{
switch(moveCount)
{
case 0:
destination = positionDuplicate + new Vector3(0, 0, 5);
moveCount += 1;
break;
case 1:
destination = positionDuplicate + new Vector3(0, 5, 0);
moveCount += 1;
break;
case 2:
destination = positionDuplicate + new Vector3(0, 0, -5);
moveCount += 1;
break;
case 3:
destination = positionDuplicate + new Vector3(0, -5, 0);
moveCount = 0;
break;
}
timeCount = 0;
}
Thread.Sleep(200);
timeCount += 1;
}
});
}

// Update is called once per frame
void Update ()
{
transform.position = threadReturn;
positionDuplicate = threadReturn;
updated = true;
}

void OnApplicationExit()
{
running = false;
Thread.Sleep(250);
}
}
12 changes: 12 additions & 0 deletions End of the Line 2/Assets/LamdaThreading.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions End of the Line 2/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.1.2f1
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file not shown.
Binary file not shown.