Unity3D学习笔记第一课
2015-06-29 08:34
323 查看
第一课程:
1.Unity类名必须与文件名保持一致
2.讲属性设置为public可以在Unity中访问
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//获取左右方向键的的值(范围为-1到1)
float amtToMove = Input.GetAxis ("Horizontal") * speed;
//使用矩阵进行平移
gameObject.transform.Translate (Vector3.right * amtToMove);
}
3.摄像机:游戏的输出画面是由摄像机所观测的场景而实现的,将游戏场景呈现到2D的计算机屏幕,有
两种投影方式为透视投影和正交投影,Unity默认为透视投影,透视投影感觉有距离感,正交投影没有距离感。
开发Unity2D游戏,需要将投影方式改为正交投影。
透视投影的三个主要参数:
FieldofView(视角),
NearClipPlane(近看平面),
FarClipPlane(远看平面)
4.GameObject对象包含transform,camera属性,GetComponet和AddComponent等方法
5.Transform实现对象的位置、旋转以及缩放
position
rotation
localScale
Translate方法
Rotate方法
6.Input.GetAxis()与Input.GetAxisRaw()检测方向键
检测上下移动
Input.GetAxis("Vertical")
检测左右移动
Input.GetAxis("Horizontal")
7.Time类
deltaTime 上一帧到本帧的时间,单位为秒
8.三个Update的调用顺序
MonoBehaviour.FixedUpdate()
MonoBehaviour.Update()
MonoBehaviour.LateUpdate()
9.循环移动方块
public class Player : MonoBehaviour {
public float playerSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log ("Update");
var moveto = Input.GetAxis ("Horizontal") *Time.deltaTime* playerSpeed;
gameObject.transform.Translate (Vector3.right * moveto);
if (transform.position.x > 9.15) {
transform.position=new Vector3(-9.15f,transform.position.y);
}
if (transform.position.x <- 9.15) {
transform.position=new Vector3(9.15f,transform.position.y);
}
}
void LateUpdate(){
Debug.Log ("LateUpdate");
}
void FixedUpdate(){
Debug.Log("FixedUpdate");
}
}
9.创建按钮并响应按钮操作
void OnGUI(){
if (GUI.Button (new Rect (0, 0, 100, 50), "Play")) {
}
else if (GUI.Button (new Rect (0, 60, 100, 50), "Pause")) {
}
else if (GUI.Button (new Rect (0, 120, 100, 50), "Stop")) {
}
}
1.Unity类名必须与文件名保持一致
2.讲属性设置为public可以在Unity中访问
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//获取左右方向键的的值(范围为-1到1)
float amtToMove = Input.GetAxis ("Horizontal") * speed;
//使用矩阵进行平移
gameObject.transform.Translate (Vector3.right * amtToMove);
}
3.摄像机:游戏的输出画面是由摄像机所观测的场景而实现的,将游戏场景呈现到2D的计算机屏幕,有
两种投影方式为透视投影和正交投影,Unity默认为透视投影,透视投影感觉有距离感,正交投影没有距离感。
开发Unity2D游戏,需要将投影方式改为正交投影。
透视投影的三个主要参数:
FieldofView(视角),
NearClipPlane(近看平面),
FarClipPlane(远看平面)
4.GameObject对象包含transform,camera属性,GetComponet和AddComponent等方法
5.Transform实现对象的位置、旋转以及缩放
position
rotation
localScale
Translate方法
Rotate方法
6.Input.GetAxis()与Input.GetAxisRaw()检测方向键
检测上下移动
Input.GetAxis("Vertical")
检测左右移动
Input.GetAxis("Horizontal")
7.Time类
deltaTime 上一帧到本帧的时间,单位为秒
8.三个Update的调用顺序
MonoBehaviour.FixedUpdate()
MonoBehaviour.Update()
MonoBehaviour.LateUpdate()
9.循环移动方块
public class Player : MonoBehaviour {
public float playerSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log ("Update");
var moveto = Input.GetAxis ("Horizontal") *Time.deltaTime* playerSpeed;
gameObject.transform.Translate (Vector3.right * moveto);
if (transform.position.x > 9.15) {
transform.position=new Vector3(-9.15f,transform.position.y);
}
if (transform.position.x <- 9.15) {
transform.position=new Vector3(9.15f,transform.position.y);
}
}
void LateUpdate(){
Debug.Log ("LateUpdate");
}
void FixedUpdate(){
Debug.Log("FixedUpdate");
}
}
9.创建按钮并响应按钮操作
void OnGUI(){
if (GUI.Button (new Rect (0, 0, 100, 50), "Play")) {
}
else if (GUI.Button (new Rect (0, 60, 100, 50), "Pause")) {
}
else if (GUI.Button (new Rect (0, 120, 100, 50), "Stop")) {
}
}
相关文章推荐
- unity, List namespace
- unity5, UGUI刺穿问题解法
- unity架构原则(摸索、增补中)
- (译)Cg Programming/Unity(Cg编程/Unity)
- Unity3D之AssetBundle学习:Android上运行笔记
- [Unity-24] Unity的四种加载场景的方法
- unity手游《摩卡世界online》全套源码(服务端+客户端+数据库)
- unity资源管理
- Unity炸弹爆炸伤害(群攻伤害)
- 学习笔记:Unity战斗卡牌游戏(一)-----NGUI基础组件使用及代码修改获取
- 游戏引擎中三大及时光照渲染方法介绍(以unity3d为例)
- unity, remove a scene from build settings
- Unity 脚本学习总结
- Unity3d之A*算法在游戏中的应用(一)
- unity, read text file
- Unity 脚本优化
- Unity性能优化
- unity, 不要试图用rigidbody.Sleep()停止rigidbody
- Unity 自定义字体 Custom Font 原理 二
- 【Unity】Mesh网格编程(四)麦比乌斯环