Debug.DrawLine()

作者:追风剑情 发布于:2016-3-3 15:26 分类:Unity3d

一、创建脚本

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DebugTest : MonoBehaviour {
  5.  
  6. public Transform cube0;
  7. public Transform cube1;
  8.  
  9. void Update()
  10. {
  11. Debug.DrawLine(cube0.position, cube1.position, Color.red);
  12. }
  13. }

 

二、创建两个Cube

11111.png

 

在Scene窗口中看到的效果

22222.png

绘制Bounds

  1. /// <summary>
  2. /// 在场景中绘制Bounds线框
  3. /// </summary>
  4. /// <param name="bounds"></param>
  5. private void DrawBounds(Bounds bounds)
  6. {
  7. #region 场景中绘制辅助线框
  8. Vector3 start = bounds.min;
  9. Vector3 end = bounds.min;
  10.  
  11. //绘制下方矩形
  12. end.x += bounds.size.x;
  13. Debug.DrawLine(start, end, Color.yellow, 30); //前
  14.  
  15. start = end;
  16. end.z += bounds.size.z;
  17. Debug.DrawLine(start, end, Color.yellow, 30);//右
  18.  
  19. start = end;
  20. end.x -= bounds.size.x;
  21. Debug.DrawLine(start, end, Color.yellow, 30);//后
  22.  
  23. start = end;
  24. end.z -= bounds.size.z;
  25. Debug.DrawLine(start, end, Color.yellow, 30);//左
  26.  
  27. //绘制前方矩形
  28. start = end;
  29. end.y += bounds.size.y;
  30. Debug.DrawLine(start, end, Color.yellow, 30);//左
  31.  
  32. start = end;
  33. end.x += bounds.size.x;
  34. Debug.DrawLine(start, end, Color.yellow, 30);//上
  35.  
  36. start = end;
  37. end.y -= bounds.size.y;
  38. Debug.DrawLine(start, end, Color.yellow, 30);//右
  39.  
  40. //绘制右方矩形
  41. end = start;
  42. end.z += bounds.size.z;
  43. Debug.DrawLine(start, end, Color.yellow, 30);//上
  44.  
  45. start = end;
  46. end.y -= bounds.size.y;
  47. Debug.DrawLine(start, end, Color.yellow, 30);//右
  48.  
  49. //绘制后方矩形
  50. end = start;
  51. end.x -= bounds.size.x;
  52. Debug.DrawLine(start, end, Color.yellow, 30);//上
  53.  
  54. start = end;
  55. end.y -= bounds.size.y;
  56. Debug.DrawLine(start, end, Color.yellow, 30);//右
  57.  
  58. //绘制左方矩形
  59. end = start;
  60. end.z -= bounds.size.z;
  61. Debug.DrawLine(start, end, Color.yellow, 30);//上
  62. #endregion
  63. }

 11111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号