unity3d和Flash常用的功能代码比较
总结一下这两个的脚本语言里面常用的功能代码,unityscript和as3。一直觉得as和js很像,而unity3d里面又用了javascript,做个比较看看。
1. 元件的显示与隐藏
UnityScript:
obj.renderer.enabled = true; // or false
Actionscript 3:
obj.visible = true; // or false
2. 元件的颜色填充
UnityScript:
thing.renderer.material.color = Color.red;
Actionscript 3:
var colorTransform:ColorTransform = new ColorTransform();
colorTransform.color = 0xFF0000;
thing.transform.colorTransform=colorTransform;
3. Math里面的随机数
UnityScript:
var someRandomNumberBetween0And5:int = Random.Range(0, 5);
Actionscript 3:
var someRandomNumberBetween0And5:int = Math.floor(Math.random()*5);
4. 键盘事件
UnityScript:
if(Input.GetKeyDown(“space”))
{
// Do stuff.
}
Actionscript 3:
stage.addEventListener(KeyboardEvent.KEY_DOWN, doKeyDown);
private function doKeyDown(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case 32:
// Space bar! Do stuff.
break;
default:
break;
}
}
5. 超链接
UnityScript:
Application.OpenURL(“http://www.untoldentertainment.com);
Actionscript 3:
navigateToURL(“new URL(“http://www.untoldentertainment.com“), “_self”);
转自:http://riacn.net/bq/unity3d%E5%92%8Cflash%E5%87%A0%E4%B8%AA%E5%B8%B8%E7%94%A8%E7%9A%84%E5%8A%9F%E8%83%BD%E4%BB%A3%E7%A0%81
