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. Android——requestWindowFeature()的应用

    Android开发中经常会在setContentView(R.layout.XXX); 前设置requestWindowFeature(XXXX). 他的意思是需要软件全屏显示.自定义标题(使用按钮等 ...

  2. Access restriction: The method typeNameToClass(String) from the type ObjectHandler is not accessible due to restriction on required library

    异常: Access restriction: The method typeNameToClass(String) from the type ObjectHandler is not access ...

  3. 【进阶修炼】——改善C#程序质量(3)

    32, 总是优先考虑泛型. 泛型代码有很好的重复利用性,和类型安全性. 33, 应尽量避免在泛型类中声明静态成员. 静态成员达不到共享的目的.List<int>和List<Strin ...

  4. 全国地区的省份、城市、区县 最新Sql脚本

    IF (EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_Province]') AND type =' ...

  5. compareTo返回值为-1 、 1 、 0 的排序问题

    1.什么是Comparable接口 此接口强行对实现它的每个类的对象进行整体排序.此排序被称为该类的自然排序 ,类的 compareTo 方法被称为它的自然比较方法 .实现此接口的对象列表(和数组)可 ...

  6. 小米路由器刷Xiaomi Mi WiFi Mini openwrt

    Current Stable Release - OpenWrt 18.06.1,released on August, 18th 2018. there is also PandoraBox fir ...

  7. Redis 实现消息队列 MQ

    Redis 2.4版本之后就内置队列的功能了,如果是日常比较简单的队列应用,可以选择Redis , 效率还很高的!! Redis 还能实现 有序 和 无序 两种队列(只讨论生产者和消费者这种模式的队列 ...

  8. mysql导入sql脚本

    例如:我的用户名是root 密码是123 sql脚本存在C盘 名字为test.sql 数据库为test 有两种方法可以执行脚本 1:打开CMD输入以下命令(不需要转换目录)>mysql -u r ...

  9. Claims-Based Authentication and Authorization

    Introduction You can download the Visual Studio solutions for this article at this location. With al ...

  10. 树莓派3 U盘启动 配置 & 即 MSD启动 总结

    树莓派3添加了一个新特性:允许USB启动.现在我们既可以从SD卡启动,也可以从USB启动.USB设备可以是U盘,带USB适配器的SSD硬盘,甚至是移动硬盘. 本文介绍怎么从U盘启动树莓派3.   1. ...