Unity3D学习之transform。
来源:互联网 发布:四川经济发展数据库 编辑:程序博客网 时间:2024/04/28 14:55
欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频、U3D教程、U3D常见问题、U3D项目源码,我们致力于打造业内unity3d培训、学习第一品牌。
1、Unity常用的必然事件。
在Unity的脚本中,可以定义一些特定的函数,这些函数会在满足某些条件时由Unity自动调用,它们被称为必然事件(Certain Events)。而Start和Update正是最常用的两个事件,因此Unity默认为新建的脚本添加了这两个事件。
(1)Awake():唤醒脚本,此方法为系统执行的第一个方法,用于脚本
的初始化,在脚本的生命周期中只执行一次。
(2)Update():正常更新,用于更新逻辑。每创建一个脚本,脚本中都
会默认添加这个方法。此方法每帧都会由系统自动调用一次。
(3)Start():此方法在Awake()方法之后,Update()方法之前执行,并且
只执行一次
(4)LateUpdate():此方法在Update()方法执行后调用,同样每一帧都
调用。
(5)FixedUpdate():固定更新,更新频率为0.02s
(6)OnGUI():OnGUI()在每一帧都会由系统自动调用一次,渲染和处理GUI事件时调用。
2、输出。
print("hello");
Debuge.Log("hello");
Debuge.LogWarning("hello");
Debuge.LogError("hello");
3、游戏对象的Transform。
Transform属性可以进行位置、旋转、大小的设置
位置:position
旋转:rotate
大小:localScale
如果要操作脚本当前使用的GameObject,则可以省略要操作的GameObjiect.
4、Vector3向量介绍。
Vector3是Unity中定义的一个含有x,y,z三个字段的类,可以表示位置点,也可以表示一个向量。Vector3乘以数值表示对向量的三个值乘以相应的值,v1-v2则表示从v2指向v1的向量。
transform.Translate(vector3)让对象沿着vector3向量的方向移动,比如transform.Translate(new Vector3(0.2f,0.2f,0))就是Z轴不动,向斜上方移动,移动的分量X、Y都是0.2f。
Vector类内置成员:up,down,left,right,forward,back,zero
写法:
transform.Translate (Vector3.forward); //向前移动(即沿Z轴移动)的语句表示。
transform.Translate (new Vector3(10,0,0)); //沿X轴移动的Vector3表示。
transform.Rotate (new Vector3(0,10,0)); //以自身远点作为本地坐标原点(0,0,0)沿Y轴旋转。
transform.localScale += new Vector3 (0.1F, 0, 0); //沿X轴左右伸长。
5、沿物体旋转。
RotateAround(v1,v2,angle),元素围绕着世界坐标的v1点采用v2向量旋转angle角度。案例:FixedUpdate中transform.RotateAround(Camera.main.transform.position,Vector3.up,0.5f)元素围绕着摄像头运动。
例题:地球围绕着太阳转。
代码:using UnityEngine;
using System.Collections;
public class Halo : MonoBehaviour {
// Use this for initialization
void Start () {}
// Update is called once per frame
void Update () {}
Vector3 Sun=new Vector3(1,9,-16);
void FixedUpdate(){
transform.RotateAround (Sun, Vector3.up, 1);
}
}
- Unity3D学习之transform。
- Unity3D之Transform参数
- Unity3D学习之(transform和Vector3向量)
- unity学习之Transform
- css3学习之:transform
- Transform介绍(Unity3D开发之二)
- Unity3d--Transform
- Unity3D-Transform
- c++X学习之transform
- STL学习之transform函数
- H5学习笔记之Transform
- unity3D游戏开发之Transform的坐标变换注意事项
- Unity3d Transform.DetachChildren使用
- Unity3d的Transform结构图
- Unity3D-Transform.TransformDirection
- unity3d的Transform结构图
- Unity3D------Transform和Input
- Unity3d变换组件(Transform)
- keeplived日志位置指定
- Android--使用TCP/IP协议实现断点上传(客户端-服务端代码)
- Eclipse快捷键大全
- javascript url编码方法 escape(), encodeURL(), encodeURIComponent() 区别
- 屡遭安全吐槽 Uber将用人体识别技术调查司机
- Unity3D学习之transform。
- CentOS 6.5 中安装与配置JDK-7 (Linux系统)
- Bat命令学习
- VLC version(版本) : 3.0.0-git,2.1.5搭建编译时遇到的问题和解决方法!
- Python程序在Android手机上运行
- Servlet如何实现修改后不重启服务器而生效
- 【LeetCode】Distinct Subsequences 解题报告
- intllij idea java.lang.AssertionError:upexpected content storage modification
- uploadify 插件文件类型判断