Vector向量的屬性與方法 u3d學習總結筆記本
阿新 • • 發佈:2018-12-09
1.Vector2(x,x)的簡寫。
2.Vector2各種屬性值
3.Vector2各種方法
//===================================
1.Vector2(x,x)的簡寫。
print(Vector2.down);//編寫Vector2(0,-1)的簡寫。 print(Vector2.up);//編寫Vector2(0,1)的簡寫。 print(Vector2.left);//編寫Vector2(-1,0)的簡寫。 print(Vector2.right);//編寫Vector2(1、0)的簡寫。 print(Vector2.one);//編寫Vector2(1、1)的簡寫。 print(Vector2.zero);//編寫Vector2(0,0)的簡寫。
2.Vector2各種屬性值
print(a.magnitude);//返回這個向量的長度(只讀)。
print(a.sqrMagnitude);//返回這個向量的平方長度(只讀)。
print(a.normalized);//返回這個向量的大小為1(只讀)。//單位化向量
//把向量變成1以內的數值,能用來表示方向
3.Vector2各種方法
print(Vector2.Angle(a,c));//返回from和to之間的角度。 //由從和到兩者返回一個角度。形象的說,從和到的連線和它們一個指定軸向的夾角。 print(Vector2.ClampMagnitude(c,2));//返回一個向量的拷貝,它的大小限制在maxLength上。//限定在2 print(Vector2.Distance(b,c));//返回a和b之間的距離。 //======================================= print(Vector2.Lerp(a,b,0.5f));//向量a和b之間的線性插值。//漸變移動 print(Vector2.MoveTowards(a,b,Time.deltaTime));//向目標移動。恆速移動 print(Vector2.LerpUnclamped(a,b,2f));//向量a和b之間的線性插值。//不限定範圍 //======================================== print(Vector2.Max(a,b));//返回最大值 print(Vector2.Min(a,b));//返回最小值 Vector2 res = b-a;//1,2 a向b的向量