Unity3D Script KeynoteII

1、使用代码操作Particle。

     //粒子对象
GameObject particle = null;
//粒子X轴方向速度
float velocity_x = 0.0f;
//粒子Y轴方向速度
float velocity_y = 0.0f;
//粒子Z轴方向速度
float velocity_z = 0.0f; void Start ()
{
//获得粒子对象
particle = GameObject.Find("ParticleSystem"); } void OnGUI()
{
//拖动设置粒子的最大尺寸
GUILayout.Label("粒子最大尺寸");
particle.particleEmitter.maxSize = GUILayout.HorizontalSlider (particle.particleEmitter.maxSize, 0.0f, 10.0f,GUILayout.Width()); //拖动设置粒子的最大消失时间
GUILayout.Label("粒子消失时间");
particle.particleEmitter.maxEnergy = GUILayout.HorizontalSlider (particle.particleEmitter.maxEnergy, 0.0f, 10.0f,GUILayout.Width()); //拖动设置粒子的最大生成数量
GUILayout.Label("粒子的最大生成数量");
particle.particleEmitter.maxEmission = GUILayout.HorizontalSlider (particle.particleEmitter.maxEmission, 0.0f, 100.0f,GUILayout.Width()); //拖动设置粒子X轴的移动速度
GUILayout.Label("粒子x轴的移动速度");
velocity_x= GUILayout.HorizontalSlider (velocity_x, 0.0f, 10.0f,GUILayout.Width());
particle.particleEmitter.worldVelocity = new Vector3(velocity_x, particle.particleEmitter.worldVelocity.y, particle.particleEmitter.worldVelocity.z); //拖动设置粒子Y轴的移动速度
GUILayout.Label("粒子y轴的移动速度");
velocity_y= GUILayout.HorizontalSlider (velocity_y, 0.0f, 10.0f,GUILayout.Width());
particle.particleEmitter.worldVelocity = new Vector3( particle.particleEmitter.worldVelocity.x,velocity_y, particle.particleEmitter.worldVelocity.z); //拖动设置粒子Z轴的移动速度
GUILayout.Label("粒子z轴的移动速度");
velocity_z= GUILayout.HorizontalSlider (velocity_z, 0.0f, 10.0f,GUILayout.Width());
particle.particleEmitter.worldVelocity = new Vector3( particle.particleEmitter.worldVelocity.x, particle.particleEmitter.worldVelocity.y,velocity_z); }

2、布料是Unity3.x引入的特色组件,是柔软的,可以变成任意形状,比如随风飘扬的旗子呈窗户上的窗帘。

3、Trail Renderer

  The Trail Renderer is used to make trails behind objects in the scene as they move about.

  可以通过以下类似代码来操作TrailRender:

     //路径渲染对象
private TrailRenderer trialRender; void Start ()
{
//获取路径渲染对象
trialRender = gameObject.GetComponent<TrailRenderer>();
} void OnGUI()
{ if(GUILayout.Button("增加宽度",GUILayout.Height()))
{
trialRender.startWidth +=;
trialRender.endWidth +=;
} if(GUILayout.Button("显示路径",GUILayout.Height()))
{
trialRender.enabled = true;
} if(GUILayout.Button("隐藏路径",GUILayout.Height()))
{
trialRender.enabled = false;
}
}

Input

1、判断按键是否按下。

         if (Input.GetKeyDown (KeyCode.W))
{
Debug.Log("您按下了W键");
} if (Input.GetKeyDown (KeyCode.S))
{
Debug.Log("您按下了S键");
} if (Input.GetKeyDown (KeyCode.A))
{
Debug.Log("您按下了A键");
} if (Input.GetKeyDown (KeyCode.D))
{
Debug.Log("您按下了D键");
} if (Input.GetKeyDown (KeyCode.Space))
{
Debug.Log("您按下了空格键");
}

2、判断按键是否抬起。

         //抬起按键
if (Input.GetKeyUp (KeyCode.W))
{
Debug.Log("您抬起了W键");
} if (Input.GetKeyUp (KeyCode.S))
{
Debug.Log("您抬起了S键");
} if (Input.GetKeyUp (KeyCode.A))
{
Debug.Log("您抬起了A键");
} if (Input.GetKeyUp (KeyCode.D))
{
Debug.Log("您抬起了D键");
} if (Input.GetKeyUp (KeyCode.Space))
{
Debug.Log("您抬起了空格键");
}

3、长按事件。使用Input.GetKey()方法判断键盘中某个键是否一直处于按下状态

         if (Input.GetKeyDown (KeyCode.A))
{
Debug.Log("A按下一次");
}
if (Input.GetKey (KeyCode.A))
{
//记录按下的帧数
keyFrame++;
Debug.Log("A连按:" + keyFrame+"帧");
}
if (Input.GetKeyUp (KeyCode.A))
{
//抬起后清空帧数
keyFrame=;
Debug.Log("A按键抬起");
}

4、使用Input.anyKeyDown() 来判断任意键是否按下,Input.anyKey()判断任意键是否被长按。

     // Update is called once per frame
void Update ()
{
if(Input.anyKeyDown)
{
//清空按下帧数
keyFrame=;
Debug.Log("任意键被按下");
} if(Input.anyKey)
{
keyFrame++;
Debug.Log("任意键被长按"+keyFrame+"帧");
} }

5、鼠标按下事件。

     void Update ()
{ if (Input.GetMouseButtonDown())
{
Debug.Log("点击鼠标左键的位置为:" +Input.mousePosition);
}
if (Input.GetMouseButtonDown())
{
Debug.Log("点击鼠标右键的位置为:" +Input.mousePosition);
}
if (Input.GetMouseButtonDown())
{
Debug.Log("点击鼠标中键的位置为:" +Input.mousePosition);
} }

6、使用Input.GetMouseButtonUp()方法可以监听鼠标抬起。

     void Update ()
{ if (Input.GetMouseButtonUp())
{
Debug.Log("鼠标抬起左键的位置为:" +Input.mousePosition);
}
if (Input.GetMouseButtonUp())
{
Debug.Log("鼠标抬起右键的位置为:" +Input.mousePosition);
}
if (Input.GetMouseButtonUp())
{
Debug.Log("鼠标抬起中键的位置为:" +Input.mousePosition);
} }

7、Input.GetMouseButton()用于监听鼠标长按事件。

         //连按事件
if(Input.GetMouseButton())
{
MouseFrame++;
Debug.Log("鼠标左键长按"+MouseFrame+"帧");
}
if(Input.GetMouseButton())
{
MouseFrame++;
Debug.Log("鼠标右键长按"+MouseFrame+"帧");
}
if(Input.GetMouseButton())
{
MouseFrame++;
Debug.Log("鼠标中键长按"+MouseFrame+"帧");
}

8、使用Input.GetAxis()获取某个自定义按键的轴值。

     void Update ()
{
float value = Input.GetAxis ("test");
Debug.Log("按键轴的数值为:"+value);
}

9、字符串转换为int。

  

Application

1、Application.LoadLevel()可以切换场景。

  

2、Application.CaptureScreenShot()可以截图。

   

3、Application.OpenURL()可以打开网页。

4、Application.Quit()退出游戏。

AssetDataBase

1、使用AssetDataBase.LoadAssetAtPath()可以设置行为。

  

2、使用AssetDataBase.CreateAsset()可以创建资源。

  

3、AssetDataBase.CreateFolder()可以创建目录。

4、AssetDataBase.CopyAsset()可以移动资源,AssetDataBase.MoveAsset()可以移动资源。

5、AssetDataBase.DeleteAsset()、AssetDataBase.Reresh()。

Unity3D Script KeynoteII的更多相关文章

  1. Unity3D Script Keynote

    [Unity3D Script Keynote] 1.创建GameObject if(GUILayout.Button("创建立方体",GUILayout.Height(50))) ...

  2. Unity3D Script Execution Order ——Question

    我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的.这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来 ...

  3. Unity3D 中的3种坐标系

    Unity3D Script API : Camera 若干文章: 1.Screen VS Viewport What is the difference 2.Screen,Viewport有什麽區別 ...

  4. 使用 Sublime Text 2 开发 Unity3D 项目

    用 Sublime 已经有很长一段时间,很舒适,很贴心,根本停不下来.之前因为是开发页游,所以是用 AS3 开发,近段时间,新开了个手游项目,引擎方面选定了 Unity3D,老实说,之前没有太多的 3 ...

  5. 完整Deploy WebPlayer的Config

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  6. [Unity菜鸟] Unity Web Player 相关问题 (待完善)

    1. 发布网页版Unity自适应网页大小 发布网页版,Unity3D自适应网页大小.这个问题困扰了我很长时间,今天终于把他解决了,给大家分享一下. 这里用Uinty4.0发布网页版,我去掉了里面的标题 ...

  7. U3D——Unity3D的脚本-script入门

     Unity3D的基本操作非常easy就能掌握了,接下来就是游戏系统的核心部分:脚本. 什么是Script(脚本)?简而言之,就是使用代码来运行一系列动作命令的特殊文本,它须要编译器来从新解读.U ...

  8. Unity3D的脚本-script入门

    来自:http://blog.163.com/shininglore@126/blog/static/961841802013412101454833/ Unity3D的基本操作很容易就能掌握了,接下 ...

  9. Unity3d基础组件 (Component) 和脚本 (Script) 关系

    原版的:http://edu.china.unity3d.com/learning_document/getData?file=/Manual/TheComponent-ScriptRelations ...

随机推荐

  1. java连接mysql的一个小例子

    想要用java 连接数据库,需要在classpath中加上jdbc的jar包路径 在eclipse中,Project的properties里面的java build path里面添加引用 连接成功的一 ...

  2. order by多个字段对索引的影响

    某前台sql语句,简化后如下SELECT products_name,products_viewed FROM `products_description` ORDER BY products_vie ...

  3. 【转】不可变数组NSArray与可变数组NSMutableArray

    原文网址:http://www.jianshu.com/p/1ad327f56d1d 不可变数组NSArray //创建一个空数组 NSArray *array = [NSArray array]; ...

  4. PHP String函数分类

    1.查找字符位置函数: strpos  ($str,search,[int]):    查找search在$str中的第一次位置从int开始: stripos ($str,search,[int]): ...

  5. Phonegap中用ajax读取PHP服务器的数据

    直接上代码: HTML: var URL="网站地址&callback=?"; $.ajax({ type : 'GET', url : URL, dataType : ' ...

  6. php.ini中Magic_Quotes_Gpc开关设置

    如果你网站空间的php.ini文件里的magic_quotes_gpc设成了off,那么PHP就不会在敏感字符前加上反斜杠(\\),由于表单提交的内容可能含有敏感字符,如单引号('),就导致了SQL ...

  7. AE+C# 图层中增加相应属性标注

    原文 AE+C# 图层中增加相应属性标注 ) { IGeoFeatureLayer pGeoFeatureLayer; ILineLabelPosition pLineLabelPosition; I ...

  8. Excel的最大行数

    使用Excel2007或Excel2010,在“另存为” 菜单中可以选择为“Excel 07-2003 工作薄”,从中我们可以看出,到了2007版以后,存储格式变了,简单一点从扩展名便可以看出,一个是 ...

  9. [搜片神器]之DHT网络爬虫的C++程序初步开源

    回应大家的要求,特地整理了一开始自己整合的代码,这样最简单,最直接的可以分析流程,至于文章里面提供的程序界面更多,需要大家自己开发. 谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器: ht ...

  10. Java并发编程-可重入锁

    可重入锁,也叫做递归锁,指的是同一线程 外层函数获得锁之后 ,内层递归函数仍可以获取该锁而不受影响.在JAVA环境下 ReentrantLock 和synchronized 都是 可重入锁. publ ...