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的更多相关文章

  1. Unity3D入门之Unity3D介绍以及编辑器的使用(1)

    1.Unity3D介绍 Unity3D是跨平台(IOS.Android.Windows Phone.Windows.Flash.XBOX360.PS3.Wii等)游戏引擎,可以开发2D.2.5D.3D ...

  2. 【Unity3D/C#】Unity3D中的Coroutine详解

    Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这样的代码. 疑问: yield是什么? Coroutine是什么? unity的coroutin ...

  3. WPF嵌入Unity3D之后,unity3D程序的键盘和鼠标事件无法触发(3D程序的焦点无法激活)的解决方案

    目前最通用的客户端调用3D的方式,就是WPF程序通过Process启动Unity3D的exe进程,直接上代码: //开启3D进程 internal void Create3DProcess(strin ...

  4. [Unity3D] 浅尝Unity3D

    01. Move and Rotate 标准全局坐标系 Keyboard using UnityEngine; using System.Collections; public class NewBe ...

  5. Unity3D笔记十七 Unity3D生命周期

    一个游戏组件的脚本有一个生命周期——一开始实例化,直到结束实例被销毁.在这期间,他们有时候处于激活状态,有时候处于非激活状态:对于活动,对用户有时候可见,有时候不可见 本文主要讨论常见脚本的的生命周期 ...

  6. 本人AI知识体系导航 - AI menu

    Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯   徐亦达老板 Dirichlet Process 学习 ...

  7. Unity3D热更新之LuaFramework篇[10]--总结篇

    背景 19年年初的时候,进到一家新单位,公司正准备将现有的游戏做成支持热更的版本.于是寻找热更方案的任务就落在了我头上. 经过搜索了解,能做Unity热更的方案是有好几种,但是要么不够成熟,要么不支持 ...

  8. Thinking in Unity3D:渲染管线中的Rendering Path

      关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...

  9. Unity3D游戏开发初探—1.跨平台的游戏引擎让.NET程序员新生

    一.Unity3D平台简介 Unity是由Unity Technologies开发的一个让轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的 ...

随机推荐

  1. Java编程的逻辑 (41) - 剖析HashSet

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  2. [算法]和为S的连续正数序列

    题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他 ...

  3. Oracel扩展表空间

    --表空间查看 SELECT tbs, sum(totalM) as total, sum(usedM) as UserdM, sum(remainedM) as remainedM, as User ...

  4. hbase 学习(十二)非mapreduce生成Hfile,然后导入hbase当中

    最近一个群友的boss让研究hbase,让hbase的入库速度达到5w+/s,这可愁死了,4台个人电脑组成的集群,多线程入库调了好久,速度也才1w左右,都没有达到理想的那种速度,然后就想到了这种方式, ...

  5. CodeWarrior WarningC12056

    C12056:SP debug info incorrect because of optimization or inline assemble 该warning是代码最优化时(common cod ...

  6. java将doc文件转换为pdf文件的三种方法

    http://feifei.im/archives/93 —————————————————————————————————————————————— 项目要用到doc转pdf的功能,一番google ...

  7. 如何利用jsp实现防盗链功能

    index.jsp ----------------------------- Place your content here here is index jsp get header info a. ...

  8. 使用Html5+CSS3的优势

    一:大多浏览器支持,低版本也没问题     我看点这方面的资料,是为了做手机应用网站(有三个方案,这个是备用方案),可以开发响应式网站,可以脱离开发平台进行跨平台.     在Html5网页中引入Mo ...

  9. Linux epoll版定时器

    #ifndef __MYTIMER_H_ #define __MYTIMER_H_ /*************** 高并发场景下的定时器 *****************/ //定时器回调函数 t ...

  10. C++ 模板 template

    #include <iostream> using namespace std; /* 模板的作用: 1. 不用声明类型, 传什么进来就是什么类型, 返回也是什么类型 2. 方法封装起来, ...