点乘和叉乘

画线

GL

源码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
public Transform tf;
public float height =4f;
public float lower = 10f;
public GameObject Target;
public Text x1,x2;
void OnPostRender(){
// GL.LoadOrtho();
GL.Begin(GL.LINES);
GL.Color(Color.green);
GL.Vertex(Target.transform.position);
GL.Vertex(tf.position);
GL.End();
}
private void LateUpdate() {
this.transform.position = tf.position-Vector3.forward*lower+Vector3.up*height;
this.transform.LookAt(tf);
// 向量
Vector3 target= Target.transform.position-tf.transform.position;
Vector3 obj = tf.transform.forward;
//计算
if(Vector3.Dot(target,obj)>0)
{
x1.text="前面";
}
else x1.text="后面";
if(Vector3.Cross(target,obj).y>0){
x2.text="左边";
}
else x2.text="右边";
//线段 点到点
// Debug.DrawLine(Target.transform.position,tf.position,Color.red);
//射线 初始点和方向,长度
Debug.DrawRay(tf.position,tf.transform.forward*10f,Color.blue);
}
// Update is called once per frame
}