[Unity3D] 浅尝Unity3D
01. Move and Rotate
标准全局坐标系

Keyboard
using UnityEngine;
using System.Collections; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.W)){
this.transform.Translate(Vector3.up, Space.World); }else if(Input.GetKey(KeyCode.S)){
this.transform.Translate(Vector3.down, Space.World); }else if(Input.GetKey(KeyCode.A)){
this.transform.Translate(Vector3.left, Space.World); }else if(Input.GetKey(KeyCode.D)){
this.transform.Translate(Vector3.right, Space.World); }else if(Input.GetKey(KeyCode.F)){
this.transform.Rotate(Vector3.right, Space.Self); // 左手坐标系 }else if(Input.GetKeyDown(KeyCode.F)){
this.transform.Rotate(Vector3.right, Space.Self); // 左手坐标系 }
}
}
Mouse
if(Input.GetMouseButton()){ // 0:left button; 1: right button
this.transform.Rotate(Vector3.right, Space.Self);
RotateAround
public Transform TranRotateObj; this.transform.RotateAround(TranRotateObj.position,Vector3.up, 1F);
围绕的目标:TranRotateObj 可以通过IDE编辑。

02. terrain and rendering
Easy and simple, but enough for me.
View

03. create GameObject
Game Objects are added dynamically.
动态生成克隆对象
using UnityEngine;
using System.Collections; public class Demo3 : MonoBehaviour { private GameObject go=null; // Global value
GameObject goClone=null; void Start ()
{
//创建Cube
go=GameObject.CreatePrimitive(PrimitiveType.Cube);
//渲染为红色。
go.renderer.material.color=Color.red; }//Start_end void Update ()
{
//学习克隆(拷贝)
if(Input.GetKeyDown(KeyCode.C))
{
goClone=(GameObject)Instantiate(go);
//改变克隆体的位置
goClone.transform.position=goClone.transform.position+new Vector3(2F,0F,0F);
} //学习销毁
if(Input.GetKeyDown(KeyCode.D))
{
Destroy(goClone);
} }//Update_end }//Class_end
动态导入其他脚本 - 调用其他脚本内的方法
1. 自动调用start(),update().
using UnityEngine;
using System.Collections; public class Demo4 : MonoBehaviour { public GameObject goObj; //需要进行赋值的游戏对象 void Start ()
{ }//Start_end void Update ()
{
if(Input.GetKeyDown(KeyCode.A))
{
//动态加载脚本。
goObj.AddComponent("RotateSelf");
} //动态销毁游戏对象所属的脚本。
if(Input.GetKey(KeyCode.D))
{
Destroy(goObj.GetComponent("RotateSelf"));
}
}//Update_end }//Class_end
2. 定时调用本类中的方法 - 回调函数
using UnityEngine;
using System.Collections; public class Demo7 : MonoBehaviour { void Start ()
{
//回调函数
//Invoke("DisplayN",5F); //5秒后执行“DisplayNum” 方法
InvokeRepeating("RepeatingDisplay",2F,0.5F); //第一个参数表示启动时间,第二个参数表示间隔时间。 }//Start_end void DisplayN()
{
Debug.Log("显示数字 22 222222。。。。");
} void RepeatingDisplay()
{
Debug.Log("我反复被执行, 你相信吗? ");
} void Update ()
{ }//Update_end }//Class_end
3. 调用其他类中的变量
using UnityEngine;
using System.Collections; public class Demo6 : MonoBehaviour { public GameObject goObj; //需要操作的对象 void Start ()
{
int intTempNum= goObj.GetComponent<Demo5>().IntNum; // goObj上的Demo5,那么至少要实例化Demo5,并挂在Demo6上(Go Obj: Demo6)
Debug.Log("[Demo6.cs]从Demo5.cs 文件中得到的数值: "+intTempNum);
}//Start_end void Update ()
{ }//Update_end }//Class_end
[Unity3D] 浅尝Unity3D的更多相关文章
- 【浅墨Unity3D Shader编程】之一 夏威夷篇:游戏场景的创建 & 第一个Shader的书写
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨) ...
- 【浅墨Unity3D Shader编程】之二 雪山飞狐篇:Unity的基本Shader框架写法&颜色、光照与材质
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40955607 作者:毛星云(浅墨) ...
- 【浅墨Unity3D Shader编程】之三 光之城堡篇:子着色器、通道与标签的写法 & 纹理混合
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://hpw123.net/a/C__/kongzhitaichengxu/2014/1117/120.html 作者:毛星云 ...
- 【浅墨Unity3D Shader编程】之中的一个 夏威夷篇:游戏场景的创建 & 第一个Shader的书写
本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨) ...
- 浅尝ECMAScript6
浅尝ECMAScript6 简介 ECMAScript6 是最新的ECMAScript标准,于2015年6月正式推出(所以也称为ECMAScript 2015),相比于2009年推出的es5, es6 ...
- 浅尝key-value数据库(二)——MongoDB的优与劣
浅尝key-value数据库(二)——MongoDB的优与劣 MongoDB的名字取自英文单词"humongous"的中间五个字母,是一个C++开发的基于分布式文件存储的数据库开源 ...
- 浅尝key-value数据库(三)——MongoDB的分布式
浅尝key-value数据库(三)——MongoDB的分布式 测试了单机MongoDB的随机读和写入性能,这一节来讲一讲MongoDB的分布式. MongoDB的分布式分成两种,一种是Replicat ...
- 浅尝key-value数据库(一)——一览NoSQL
浅尝key-value数据库(一)——一览NoSQL 最近由于一个项目的关系,研究了一下key-value数据库这个最近很火的概念.本系列从项目需求的角度分析并测试了几个key-value数据库的性能 ...
- Python图形界面开发编程:wxPython(浅尝篇)
Python 提供了多个图形开发界面的库,几个常用 Python GUI 库如下: Tkinter: Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 .Tk 和 ...
随机推荐
- 解决pageControl页面设置无效问题
废话不多说,先上代码 1.添加pageViewControl - (void)addPageControl { UIPageControl *pageControl = [[UIPageControl ...
- MyEclipse8.6中提交SVN报错
上周五(11月27日)的时候,从TortoiseSVN提交项目报错,然后直接从MyEclipse中检出来,修改后提交同样报错. MyEclipse8.6中提交SVN报错,错误提示如下: commit ...
- 数据采集:完美下载淘宝Ip数据库 简单的程序节省60元人民币而不必购买数据库
曾经做网站类型的程序时,经常需要收集客户端的访问数据,然后加以分析.这需要一个Ip数据库,数据表中显示Ip所在的省份市区等信息.网络上有流传的Ip纯真数据库,一些公开的Web服务也可以查询Ip地址信息 ...
- Bruce Eckel:编程生涯(转载)
Bruce Eckel:编程生涯(转载) 说明:Bruce Eckel 著有大名鼎鼎的<Thinking in C++>和<Thinking in Java>.本文是他对程序员 ...
- windows 隐藏文件方法
隐藏: 然后在里面输入:attrib +s +a +h +r f:\123 (f的意思就是F盘,123就是你新建的文件夹名字),然后按回车,你会发现F盘下的123文件夹不见的,其实就是被你隐藏了. 文 ...
- mac电脑如何不生成.DS_STORE文件
执行这个命令,然后重启 defaults write com.apple.desktopservices DSDontWriteNetworkStores true
- Splunk - 如何在WebFramework之CORS模式下你的网站和splunk web进行交互
1. 修改配置文件以支持CORS 进入/Applications/Splunk/etc/system/local 修改server.conf 在最后加入如下: [httpServer]crossOri ...
- System.Diagnostics.Debug和System.Diagnostics.Trace 【转】
在 .net 类库中有一个 system.diagnostics 命名空间,该命名空间提供了一些与系统进程.事件日志.和性能计数器进行交互的类库.当中包括了两个对开发人员而言十分有用的类——debug ...
- Flipping elements with WPF
http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...
- <欧奈尔制胜法则—如何在股市中赚钱>读书笔记
在选择个股建仓时,要选择那些在最近季度报表中,每股收益比上年同期要有较大增幅的股票. 每股收益是指公司税后净利润除以公司普通股的总股本 选择年增长率为25%--50%的公司 年度盈利和季度盈利都要出色 ...