hello world of unity3d
2014-03-11 17:29
267 查看
unity3D入门系列一,Hello 3D World(C#脚本版)
马上要开始采用Unity3D做项目,于是本人快速参考了些资料。并把这些东西作为入门教程逐步更新到网站上来。
首先来熟悉下Unity3D的文件结构:
Assets:简单理解就是工程文件夹。分为2个1格式标准Assets,1个是手机版Assets, 手机版是个简版,说明文件上说是简化了Shader. Assets有场景文件.unity. 导入工程时候默认是没有场景的,一定要选择1个场景才能看到图形。里面一些具体的文件可以参照官方网站说明。
Library:库文件,动态链接库及Unity3D自己的二进制格式文件
Temp:临时文件夹,运行时候才会有内容
Unity3D图形显示部分几乎全部是导入已经做好的3D模型文件,导入方法很简单。这里不再说明。
首先还是来个传统的Hello World程序。这个3D场景很简单很基本:地形平面,球体,光源,摄像机。
1.新建工程命名为hello_3d_world,推荐大家文件名不要带空格全部小写,移植有好处。
2.创建地形平面:Terrain -> Create Terrain Postion和Rotation的XYZ全部清0,Scale XYZ全部写1,在Hierarchy面板中按F2将其重命名为myScene
3.默认会有1个摄像机,那个摄像机可以不用理会,当然删除他你会看不到场景中的东西。新建1摄像机GameObject->Create Other -> Camera移动到合适的位置:推荐Postion XYZ(2,0,-1.5) , Rotation XYZ 0, Scale
XYZ 1
4.新建1球体GameObject->Create Other -> Sphere Postion XYZ(3,1,3) , Rotation XYZ 0, Scale XYZ 1
5.新建点光源GameObject->Create Other -> SpotLight Postion XYZ(3,1,-3) , Rotation XYZ 0, Scale XYZ 2
小技巧:在Hierarchy面板中选中要查看的物体,然后在可视化区域内按F键能快速找到想要找到的物体。
6.新建C#脚本:Assets -> Create -> C Sharp script. 在Project 面板中按F2将其重命名为:testCamaraMovScript,双击其,点击Edit按钮编写内容如下:
这个Demo很简单,但是却包含了构成3D世界的基本内容.
马上要开始采用Unity3D做项目,于是本人快速参考了些资料。并把这些东西作为入门教程逐步更新到网站上来。
首先来熟悉下Unity3D的文件结构:
Assets:简单理解就是工程文件夹。分为2个1格式标准Assets,1个是手机版Assets, 手机版是个简版,说明文件上说是简化了Shader. Assets有场景文件.unity. 导入工程时候默认是没有场景的,一定要选择1个场景才能看到图形。里面一些具体的文件可以参照官方网站说明。
Library:库文件,动态链接库及Unity3D自己的二进制格式文件
Temp:临时文件夹,运行时候才会有内容
Unity3D图形显示部分几乎全部是导入已经做好的3D模型文件,导入方法很简单。这里不再说明。
首先还是来个传统的Hello World程序。这个3D场景很简单很基本:地形平面,球体,光源,摄像机。
1.新建工程命名为hello_3d_world,推荐大家文件名不要带空格全部小写,移植有好处。
2.创建地形平面:Terrain -> Create Terrain Postion和Rotation的XYZ全部清0,Scale XYZ全部写1,在Hierarchy面板中按F2将其重命名为myScene
3.默认会有1个摄像机,那个摄像机可以不用理会,当然删除他你会看不到场景中的东西。新建1摄像机GameObject->Create Other -> Camera移动到合适的位置:推荐Postion XYZ(2,0,-1.5) , Rotation XYZ 0, Scale
XYZ 1
4.新建1球体GameObject->Create Other -> Sphere Postion XYZ(3,1,3) , Rotation XYZ 0, Scale XYZ 1
5.新建点光源GameObject->Create Other -> SpotLight Postion XYZ(3,1,-3) , Rotation XYZ 0, Scale XYZ 2
小技巧:在Hierarchy面板中选中要查看的物体,然后在可视化区域内按F键能快速找到想要找到的物体。
6.新建C#脚本:Assets -> Create -> C Sharp script. 在Project 面板中按F2将其重命名为:testCamaraMovScript,双击其,点击Edit按钮编写内容如下:
using UnityEngine; using System.Collections; public class testCamaraMovScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { //此处为每帧刷新,不是按时间来写的,如果是逻辑代码请写在按时间计算的方法里面 //Input为获取输入按键,Iphone和Android输入不同,具体请参照帮助文件 if ( Input.GetKey ("up")) { print ("up arrow key is held down"); transform.Translate(0 , 2 * Time.deltaTime , 0); } if ( Input.GetKey("down" )) { print ("down arrow key is held down"); transform.Translate(0 , -2 * Time.deltaTime , 0); } if ( Input.GetKey ("left")) { print ("left arrow key is held down"); transform.Translate(-2 * Time.deltaTime , 0 , 0); } if ( Input.GetKey("right" )) { print ("right arrow key is held down"); transform.Translate(2 * Time.deltaTime , 0, 0); } if ( Input.GetKey ("w")) { print ("z up arrow key is held down"); transform.Translate(0 , 0 , 2 * Time.deltaTime); } if ( Input.GetKey("s" )) { print ("z down arrow key is held down"); transform.Translate(0 , 0, -2 * Time.deltaTime); } } }将其拖放到Camara或球体上,运行观看其不同的效果。
这个Demo很简单,但是却包含了构成3D世界的基本内容.
相关文章推荐
- The Connected World(Chapter 7 of Hello, Android)
- Scala: Under The Hood of Hello World
- "hello world" of MPI version
- The True Story of Hello World
- Python sample code of hudson remote api, my first Python hello world
- hello world of hibernate Annotation
- The Obligatory Hello World Example(Chapter 2 of XSLT 2nd Edition)
- helloworld program of Linden Scripting Language
- Chapter 1 Hello, world of concurrency in C++!
- List of Hello World Programs in 200 Programming Languages
- [pluto]hello world of pluto portlet
- HelloWorld App of ffmpeg JNI
- 名词王国里的死刑(翻译) A Story of Hello World
- List of Hello World Programs in 200 Programming Languages
- 【Hello Python World】Class Notes of Week 5
- C++11 多线程编程《C++ Concurrency in Action》读书笔记(1)-Hello World of Concurrency in C++
- The True Story of Hello World
- Hello, JIT World: The Joy of Simple JITs
- AddOns for World of Warcraft 之 “Hello, WoW!”
- hello jit world joy of simple jits