Ok i want to be able to create a thread.
in c# I do this
using UnityEngine;
using System.Collections;
using System.Threading;
public class threadScript : MonoBehaviour {
void print()
{
Debug.Log("Hi from another thread!");
}
// Use this for initialization
void Start () {
// Create the thread object, passing in the Alpha.Beta method
// via a ThreadStart delegate. This does not start the thread.
Thread oThread = new Thread(new ThreadStart(print));
// Start the thread
oThread.Start();
// Spin for a while waiting for the started thread to become
// alive:
while (!oThread.IsAlive);
// Put the Main thread to sleep for 1 millisecond to allow oThread
// to do some work:
Thread.Sleep(1);
// Request that oThread be stopped
oThread.Abort();
// Wait until oThread finishes. Join also has overloads
// that take a millisecond interval or a TimeSpan object.
oThread.Join();
Debug.Log("print has finished");
try
{
Debug.Log("Try to restart the print thread");
oThread.Start();
}
catch (ThreadStateException)
{
Debug.Log("ThreadStateException trying to restart print. ");
Debug.Log("Expected since aborted threads cannot be restarted.");
}
}
// Update is called once per frame
void Update () {
}
}
or something like that when I do my thread (something more advanced that just shows that you can create a thread in c#.
I mainly use javascript though so is there anyway for example say make a function in c# to create a thread and stop one etc. which I can call in my javascript script (I’ve tried and failed)
how can I create a thread in javascript?
Edit: yes this is code from Microsoft’s website made to work in unity but it still works in unity and not my point.