I started working with threads just to experiment, maybe use it for my pathing, and i was wondering how to typecast methods? also how would you do do a delegate in javascript? or some form of method hoding
I have this working, but want to make a static function I can call from anywhere to get a thread started, or something of the like.
#pragma strict
import System.Threading;
var myBool:boolean=true;
function Start(){
var ts:ThreadStart=new ThreadStart(MyThreadRunner);
var myThread:Thread=new Thread(ts);
myThread.Start();
}
function MyThreadRunner(){
while(myBool){
Thread.Sleep(1000);
Debug.Log("Still going!");
myBool = !myBool;
}
}
BTW: I can replace
var ts:ThreadStart=new ThreadStart(MyThreadRunner);
with
var ts:ThreadStart=new ThreadStart(Answers.PrintWin);
to call a static function PrintWin on class Answers, but how would I typecast that?
how would i typecast a var to put in the new TreadStart situation like a delegate?
I know I'm repeating the question, just trying to get a clear response.
↧