1.点乘用于判断向量之间的前后关系
2.叉乘用于判断向量之间的左右关系
3.数乘可对向量长度进行缩放。
1 public Transform A; 2 public Transform B; 3 4 5 private void Start() 6 { 7 if (Vector3.Dot(transform.forward,A.position) == 0) 8 { 9 print("A 在正左方或者正右方"); 10 } 11 if (Vector3.Dot(transform.forward, A.position) < 0) 12 { 13 print("A 在后方"); 14 15 } 16 if (Vector3.Dot(transform.forward, A.position) > 0) 17 { 18 print("A 在前方"); 19 } 20 if (Vector3.Dot(transform.forward, B.position) == 0) 21 { 22 print("B 在正左方或者正右方"); 23 } 24 if (Vector3.Dot(transform.forward, B.position) < 0) 25 { 26 print("B 在后方"); 27 28 } 29 if (Vector3.Dot(transform.forward, B.position) > 0) 30 { 31 print("B 在前方"); 32 } 33 34 35 if (Vector3.Cross(transform.forward, A.position).y == 0) 36 { 37 print("A 在正前或者正后方"); 38 } 39 if (Vector3.Cross(transform.forward, A.position).y < 0) 40 { 41 print("A 在左方"); 42 43 } 44 if (Vector3.Cross(transform.forward, A.position).y > 0) 45 { 46 print("A 在右方"); 47 } 48 if (Vector3.Cross(transform.forward, B.position).y == 0) 49 { 50 print("B 在正前或者正后方"); 51 } 52 if (Vector3.Cross(transform.forward, B.position).y < 0) 53 { 54 print("B 在左方"); 55 56 } 57 if (Vector3.Cross(transform.forward, B.position).y > 0) 58 { 59 print("B 在右方"); 60 } 61 62 63 }