[Unity3D] 01 - Try 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] 01 - Try Unity3D的更多相关文章
- Unity3D入门之Unity3D介绍以及编辑器的使用(1)
1.Unity3D介绍 Unity3D是跨平台(IOS.Android.Windows Phone.Windows.Flash.XBOX360.PS3.Wii等)游戏引擎,可以开发2D.2.5D.3D ...
- 【Unity3D/C#】Unity3D中的Coroutine详解
Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这样的代码. 疑问: yield是什么? Coroutine是什么? unity的coroutin ...
- WPF嵌入Unity3D之后,unity3D程序的键盘和鼠标事件无法触发(3D程序的焦点无法激活)的解决方案
目前最通用的客户端调用3D的方式,就是WPF程序通过Process启动Unity3D的exe进程,直接上代码: //开启3D进程 internal void Create3DProcess(strin ...
- [Unity3D] 浅尝Unity3D
01. Move and Rotate 标准全局坐标系 Keyboard using UnityEngine; using System.Collections; public class NewBe ...
- Unity3D笔记十七 Unity3D生命周期
一个游戏组件的脚本有一个生命周期——一开始实例化,直到结束实例被销毁.在这期间,他们有时候处于激活状态,有时候处于非激活状态:对于活动,对用户有时候可见,有时候不可见 本文主要讨论常见脚本的的生命周期 ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- Unity3D热更新之LuaFramework篇[10]--总结篇
背景 19年年初的时候,进到一家新单位,公司正准备将现有的游戏做成支持热更的版本.于是寻找热更方案的任务就落在了我头上. 经过搜索了解,能做Unity热更的方案是有好几种,但是要么不够成熟,要么不支持 ...
- Thinking in Unity3D:渲染管线中的Rendering Path
关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...
- Unity3D游戏开发初探—1.跨平台的游戏引擎让.NET程序员新生
一.Unity3D平台简介 Unity是由Unity Technologies开发的一个让轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的 ...
随机推荐
- 开源网站访问统计系统Piwik
http://www.piwik.cn/ http://www.piwik.org/ Piwik 是一套基于 Php+MySQL 技术构建,能够与 Google Analytics 相媲美的开源网站访 ...
- python 查找文件内容
输入查找的文件夹路径,要查找的内容关键字(可以指定多个),要查找的文件类型(可以是多个),搜索出符合条件的文件,并记录所有符合条件的行号及行内容. 写的感觉有点冗余,但好歹还能使用^-^,主要是方便手 ...
- drupal 不错的网址
1.最重要的7个Drupal内核模板文件 http://mydrupal.org/%E6%9C%80%E9%87%8D%E8%A6%81%E7%9A%847%E4%B8%AAdrupal%E5%86% ...
- ubuntu14.04 3D桌面效果制作
参考:http://www.360doc.com/content/14/0919/22/11681374_410808557.shtml
- 安装Nginx+Lua+OpenResty开发环境配置全过程实例
安装Nginx+Lua+OpenResty开发环境配置全过程实例 OpenResty由Nginx核心加很多第三方模块组成,默认集成了Lua开发环境,使得Nginx可以作为一个Web Server使用. ...
- Servlet、Filter、Listener总结
servlet规范提供了一组标准的servlet api.servlet容器就是servlet规范的实现. 1.In Action (1)写一个类继承HttpServlet: (2)重写其中的方法. ...
- qt configure参数配置介绍
======================================全文是按照./configure -help来翻译的==================================== ...
- 解决DoubanFM第三方客户端UI线程与工作线程交互问题
最新文章:Virson's Blog 首先要感谢yk000123的慷慨开源,开源地址见:http://doubanfm.codeplex.com/ 最近正好在学习WPF,然后在Codeplex上找到了 ...
- 关于socket的知识总结
简单点说: 阻塞就是干不完不准回来, 非组赛就是你先干,我现看看有其他事没有,完了告诉我一声 我们拿最常用的send和recv两个函数来说吧... 比如你调用send函数发送一定的Byte,在系 ...
- How to revert your file&folder by "FOUND.000"
当你在硬盘分区间复制很多文件时,当你使用下载软件时,当你用Word写作时,如果忽然遇见停电.Windows失去响应或者系统自动重新启动,在看着屏幕一黑的瞬间你会有何感受?只能希望在重新启动以后重要的文 ...