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. CSS控制背景

    一.设置背景颜色:background-color 十六进制 background-color:#ff0000; 英文名称 background-color:red; 三原色 background-c ...

  2. core--主线程

    windows的线程是windows可以分配给cpu的最小单元,对window应用程序的管理,最小的管理单位就是线程.那什么是线程?线程其实什么都不是,只是一个概念,没有实体,又看不见.这个概念的定义 ...

  3. HDU 2830 Matrix Swapping II

    给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...

  4. ASP.NET 4的Demo实践:URL路由改进支持

    从.NET框架3.5 SP1开始,微软推出了ASP.NET路由支持,从而实现了特定资源的URL与其对应的Web服务器上的物理文件之间的彻底解耦.借助于ASP.NET路由支持,开发人员可以定义一组路由规 ...

  5. BZOJ 2429 聪明的猴子

    kruskal. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  6. Windows Azure移动终端云服务管理(公测版)

    概览 云在远方,管理在您手中.在这个移动为先 云为先的世界,服务不再是基于请求才提供,而是主动来到身边方便您的模式了.我们最近将会陆续推出几大移动端利器帮助您随时随地管理您的云服务. 首批利器之中排名 ...

  7. php的setcookie

    不同浏览器对cookie的原理不同,导致cookie的过期时间有些模糊. 经测试:火狐浏览器的cookie过期时间设置是根据增量原则.服务器端设置time()+num,或者time()-num,传递到 ...

  8. redis 在centos下的安装部署

    安装的redis版本是 redis-3.0.2 请严格按照以下步骤进行 可以免除以下错误 1 make[2]: cc: Command not found 异常原因:没有安装gcc 解决方案:yum ...

  9. datawindow.net数据窗口卡片设置滚动条位置

    int pos = Convert.ToInt32(dw1.Describe(colname + ".y")); pos = pos - 40; dw1.Modify(" ...

  10. 嵌入式 hi3518平台多路码流添加osd

    <span style="font-family:Courier New;"> /******************************************* ...