using UnityEngine;
/// <summary>
/// descript:射线反射
/// author: wushengnuo
/// </summary>
public class RayReflect : MonoBehaviour
{
public Transform p1;
public Transform p2;
private void Update()
{
RaycastHit hit;
Vector3 direction = p2.position - p1.position;
direction.Normalize();
if (Physics.Raycast(p1.position, direction, out hit))
{
rayPoint = hit.point;
Vector3 reflect= Vector3.Reflect(direction, hit.normal);
reflectRayEnd = reflect * 100+hit.point;
}
}
Vector3 rayPoint;
Vector3 reflectRayEnd;
public void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(p1.position, rayPoint);
Gizmos.DrawLine(rayPoint, reflectRayEnd);
}
}
Unity 射线反射
最新推荐文章于 2024-09-27 11:49:38 发布