b站Unity学习笔记
链接:https://www.bilibili.com/video/BV12s411g7gU?p=169
静态变量
相对于世界坐标还是自身坐标,具体看运用语境。
实例变量
当比较向量大小时使用sqrMagnitude省性能。
静态函数
Normalize() 将向量本身设置为单位向量
normalized 根据向量返回一个他的单位向量
Vector3 vect = new Vector3(0,0,10);
Vector3 norm = vect.normalized; //0 0 1
vect.Normalize(); //将vect设置为 0 0 1
public AnimationCurve curve;
private float x;
private Vector3 targetPos = new Vector3(0,0,10);
/// <summary>
/// 持续时间
/// </summary>
public float duration = 1;
//移动
private void OnGUI()
{
if (GUILayout.RepeatButton("MoveTowards"))
{
//将当前物体移动到 0 0 10位置,需要有一个过程
//匀速移动 可以到达目标点
this.transform.position =
Vector3.MoveTowards(this.transform.position,targetPos,0.1f);
}
if (GUILayout.RepeatButton("Lerp"))
{
//将当前物体移动到 0 0 10位置,需要有一个过程
//先快后慢 不能到达目标点 但无限接近
//终点 和 比例固定
this.transform.position =
Vector3.Lerp(this.transform.position, targetPos, 0.1f);
//不可以超过终点
}
if (GUILayout.RepeatButton("LerpUnclamped"))
{
x += Time.deltaTime/duration;
//自然运动 起点固定 终点固定 比例根据曲线变化
this.transform.position =
Vector3.LerpUnclamped(Vector3.zero, targetPos, curve.Evaluate(x));
//可以超过终点
}
}
//投影
Vector3 result = Vector3.ProjectOnPlane(t1.position,planeNorm);
Debug.DrawLine(Vector3.zero,result,Color.yellow);
Debug.DrawLine(Vector3.zero, t1.position);