赞
踩
/// <summary> /// 射线碰撞检测,正向与反向检测 /// </summary> private bool CheckCloud() { RaycastHit hit; Ray rayForward = new Ray(LinBroth.transform.position, LinBroth.transform.TransformDirection(Vector3.forward)); if (Physics.Raycast(rayForward, out hit, 3000)) { Debug.DrawRay(LinBroth.transform.position, LinBroth.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); Debug.Log("Did Hit+正向射线"); return true; } //反向射线 Ray rayback = Reverse(rayForward, 3000); if (Physics.Raycast(rayback, out hit, 3000)) { Debug.DrawRay(LinBroth.transform.position, LinBroth.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); Debug.Log("Did Hit+反向射线"); return true; } return false; } /// <summary> /// 反转射线 /// </summary> public Ray Reverse(Ray ray, float distance) { return new Ray( ray.origin + ray.direction * distance, -ray.direction); }
在Unity2018.1.18上不大好用。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。