unity中简单的js脚本
来源:互联网 发布:淘宝开店宝软件 编辑:程序博客网 时间:2024/05/28 18:43
GUI脚本
#pragma strictvar probArray:float[];private var probValue:int;function OnGUI(){ if(GUI.Button(Rect(10,70,50,30),"Click")) { probValue=Choose(probArray); switch(probValue) { case 1: Debug.Log("npc向我敬礼"); break; case 2: Debug.Log("npc向我离开"); break; default: Debug.Log("nothing"); break; } }}function Start () {}function Update () {}function Choose(probs:float[]){ var total=0.0; for(elem in probs) { total+=elem; } var randomPoint =Random.value*total; var i:int; for(i=0;i<probs.Length;i++) { if(randomPoint<probs[i]) { return i; } else { randomPoint-=probs[i]; } } return probs.Length-1;}
随机函数
#pragma strictfunction Start () { var a:float; a=Random.value; var b:int; var c:float; b=Random.Range(1,100); c=Random.Range(0.0,10.0); Debug.Log("a的值为 "+a+"\n b:"+b+"c: "+c);}function Update () {}
Time函数
#pragma strictfunction Start () { Do(); print("print");}function Update () { GetComponent.<Light>().range+=20.0*Time.deltaTime;}function OnGUI(){ GUILayout.Label("当前时间: "+Time.time); GUILayout.Label("上一帧时间 : "+Time.deltaTime);}function Do(){ Debug.Log(Time.time); yield WaitForSeconds(5.0); Debug.Log(Time.time);}
object函数
#pragma strictvar target:GameObject;function Start () { target=GameObject.FindGameObjectWithTag("Finish"); // target=GameObject.Find("/Main Camera/Sphere"); target.GetComponent.<Renderer>().material.color=Color.red;}function Update () { }
事件
#pragma strictfunction Start () {}function Update () {}function OnGUI(){ var e:Event=Event.current; if(e.button==0&&e.isMouse) { Debug.Log("鼠标左键\n"); } if(Input.GetKey("down")) { print("按下down\n"); } if(Input.GetKey(KeyCode.UpArrow)) { print("UpArrow键\n"); } if(Input.GetButtonDown("Fire1")) { print("fire\n"); }}
虚拟轴控制移动
#pragma strictvar speed:float=10.0;var rotationSpeed:float=100.0;function Update () { var translation:float=Input.GetAxis("Vertical")*speed; var rotation:float=Input.GetAxis("Horizontal")*rotationSpeed; translation *=Time.deltaTime; rotation *=Time.deltaTime; transform.Translate(0,0,translation); transform.Rotate(0,rotation,0);}
刚体中的脚本
#pragma strictfunction OnTriggerEnter(other:Collider){ Destroy(other.gameObject);} //要开启 is Trigger 出发碰撞//鼠标按下就 增加力function FixedUpdate(){ if(Input.GetMouseButton(0)) { GetComponent.<Rigidbody>().AddForce(0,100,0); }}//一般添加在主角里function OnCollisionEnter(collision:Collision){ print(collision.gameObject);//打印被撞的物体 if(collision.rigidbody) { collision.rigidbody.AddForce(0.0,5.5,0.0); }}
0 0
- unity中简单的js脚本
- 【Unity】Unity中使用C#脚本调用JS脚本的使用方法
- Unity中脚本的生命周期
- unity中js脚本与c#脚本互相调用
- unity中js脚本与c#脚本互相调用
- Unity中CS脚本于JS脚本交互
- Unity脚本:简单的角色换装Demo
- Unity简单修改UV的动画脚本
- 一个简单的JS脚本
- Unity简单脚本
- Unity中扫雷游戏的脚本编写
- unity脚本中内部类的使用
- unity脚本中方法的生命周期
- Unity中如果去掉脚本的勾选框
- unity脚本中[SerializeField]的使用
- unity的js脚本转c#的工具
- Unity(2) 脚本简单操作
- 关于Unity内部脚本如何工作的简单概览
- Cookie中保存中文出错HTTP Status 500-
- Kali安装笔记20170202
- 最近一段时间的总结
- 带验证码的HTML5登陆页面
- [LeetCode]236. Lowest Common Ancestor of a Binary Tree
- unity中简单的js脚本
- <!DOCTYPE html>很重要
- 基于openstack构建私有云实践
- java获取mysql表结构
- 面向小数据集构建图像分类模型
- [Codeforces Round #373 DIV1C (CF718C)] Sasha and Array
- 《剑指offer》--- 在O(1)时间内删除链表结点 和 调整数组顺序使得奇数位于偶数前面
- Codeforces Round #394 (Div. 2) Dasha and Very Difficult Problem
- oracle数据同步实例