Skip to content

implement unity StartCoroutine

sonygod edited this page Dec 29, 2014 · 4 revisions

it's very easy use :

current.SetTimeout(Function, time);

**note**:current luaxe have a bug, instance Method alway compilie to static method.

so I have to fixed by hand in TypeCheck.hx

here is example code.

package ;
import luaxe.Lua;
import unityengine.*;
using Reflect;
using unityHelper.TypeCheck;
class Main 
{
	public static var mMain:Main;

	
	public var current:MonoBehaviour;
	public function new() {
		
		
	untyped __call__(SetMain, this);
	}
	@:keep	  function Awake() {
		
		
	  current.SetTimeout(delay, 2);
			
	}
	
	@:keep public 	function delay() {
		trace("delay10 " );
		
	}
	
	
public static function main()
	{
		
	mMain =	new Main();
	
	}
}

extra helper.hx

package unityHelper ;

/**
 * TypeCheck
 * @author sonygod
 */
class TypeCheck 
{

	public static function isNull(target:Dynamic):Bool {
		
		return target.ToString() == "null";
	}
	
	public static	function SetTimeout(target:Dynamic,func, sec:Float):Void {
		untyped __lua__("target:UnityCoroutine(WaitForSeconds(sec), func)");
	}
   
	
	
}
Clone this wiki locally