[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 和 ...
随机推荐
- Revit自定义快递访问工具栏
Revit快速访问工具栏提供了了一些常用的绘图工具,Revit默认的快速访问工具栏在Revit界面标题栏最左边,我们可以对快速访问工具栏进行控制,比如添加删除绘图命令,让其显示在功能区下方,编辑分组, ...
- GTD时间管理(3)---梳理总结
一:收集箱 1:灵感和想法 2:交代事情 3:任何困扰你的事 二:清单容器 1:通过行动性和非行动性原则 2:通过2分钟原则 3:通过人员性质原则 三:组织 (人,事,时 的组合 ...
- 最详细的Linux YUM命令使用教程
YUM(Yellow dog Updater, Modified)为多个Linux发行版的前端软件包管理器,例如 Redhat RHEL, CentOS & Fedora. YUM通过调用R ...
- sublime3 配置node build环境
折腾了很久,原来如此简单 1.package control 安装nodejs 2.修改Nodejs.sublime-settings文件,将nodejs路径修改成自己的 3.sublime tex ...
- Putty & Ctrl+s 的魔咒
Long long ago“ 某些旧的”哑终端“会在发送过来的数据太多,显示速度跟不上时发送一个Ctrl+s让对方等一下,然后再准备好继续显示时发送一个Ctrl+q.Putty“兼容”了这个特性.也有 ...
- Python中import的使用
python中的import语句是用来导入模块的,在python模块库中有着大量的模块可供使用,要想使用这些文件需要用import语句把指定模块导入到当前程序中. import语句的作用 import ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- SQL 性能调优日常积累【转】
阅读目录 (1)选择最有效率的表名顺序(只在基于规则的优化器中有效) (2)WHERE子句中的连接顺序 (3)SELECT子句中避免使用 ‘ * ‘ (4)减少访问数据库的次数 (5)在SQL*Plu ...
- iPhone私有API
一.基本知识 iPhone中的API除了公开的API:Published API外(或者叫文档中记录的API:Documented API),还有两类API:私有API:Private API和未公开 ...
- Visual Studio 新建项目报错" this template attempted to load component assembly 'NuGet.VisualStudio.Interop, ….".
"Error: this template attempted to load component assembly 'NuGet.VisualStudio.Interop, Version ...