Unity3d
来源:互联网 发布:ubuntu键盘左alt没反应 编辑:程序博客网 时间:2024/06/06 01:15
Transform
Transform
组件控制游戏对象在场景中的位置、旋转和大小比例,每个游戏对象都包含一个Transform组件。
成员变量:
成员函数:
// 物体向前移动void Update () { var speed=2.0f; transform.Translate(Vector3.forward * Time.deltaTime* speed); }
// 绕自身Y轴旋转void Update () { var speed=30.0f; //Time.deltaTime表示距上一次调用所用的时间。 transform.Rotate(Vector3.up * Time.deltaTime*speed); }
// 物体绕世界坐标轴Y轴旋转void Update(){ var speed = 30.0f; transform.RotateAround(Vector3.zero, Vector3.up, speed * Time.deltaTime);}// RotateAround源码/// <summary>/// <para>Rotates the transform about axis passing through point in world coordinates by angle degrees.</para>/// </summary>/// <param name="point"></param>/// <param name="axis"></param>/// <param name="angle"></param>public void RotateAround(Vector3 point, Vector3 axis, float angle){ Vector3 position = this.position; Vector3 vector3 = Quaternion.AngleAxis(angle, axis) * (position - point); this.position = point + vector3; this.RotateAroundInternal(axis, angle * ((float) Math.PI / 180f));}
Time
Unity中可以通过Time类来获取和时间有关的信息,可以用来计算帧率,调整时间流速等功能。Time类包含了一个重要的变量就是deletaTime
,它表示距上一次调用所用的时间。
成员变量:
Random
Random用于生成随机数。
成员变量:
成员函数:
Mathf
成员变量:
成员函数:
利用Mathf.SmoothDamp
函数可以制作相机的缓冲跟踪效果,让物体的移动不是那么僵硬,而是做减速的缓冲效果。
public class SmoothDamp : MonoBehaviour{ public Transform target; public float smoothTime = 0.3F; private float yVelocity = 0.0F; // Update is called once per frame void Update() { float newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y, ref yVelocity, smoothTime); transform.position = new Vector3(transform.position.x, newPosition, transform.position.z); }}
Coroutine(协同程序)
Coroutine
也称为协同程序或者协程,协同程序可以和主程序并行运行,和多线程类似。协同程序可以用来实现让一段程序等待一段时间后继续运行的有效结果。
和协同有关的函数:
阅读全文
0 0
- Unity3D
- Unity3D
- Unity3D
- Unity3D
- unity3d
- Unity3D
- Unity3D
- Unity3D
- UNITY3D
- Unity3D
- unity3d
- unity3D
- Unity3D
- Unity3d
- Unity3D
- unity3D
- unity3D
- Unity3D
- gcc编译与gdb调试
- PopUpWindow使用详解(一)——基本使用
- hdu 1542 扫描线+线段树
- Spark性能优化之数据倾斜技术方案
- 2017.8.27 阿里巴巴算法工程师笔试(2)
- Unity3d
- C++之数组名和指针的区别---补充(10)《Effective C++》
- PopUpWindow使用详解(二)——进阶及答疑
- 2017暑假第二阶段第六场 总结
- Nginx多Server反向代理配置
- 提升方法AdaBoost
- Oracle学习笔记(二) 数据库卸载
- [NOIP模拟赛]虫图
- HNOI 2004 宠物收养所(Splay树)