TestCube.cs 850 B

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TestCube : MonoBehaviour {
  4. void OnDrawGizmos()
  5. {
  6. var direction = transform.TransformDirection(Vector3.up) * 5; // 在物体的前方绘制一个5米长的线
  7. Gizmos.color = Color.green;
  8. Gizmos.DrawRay(transform.position, direction);
  9. DrawShexian();
  10. }
  11. void OnDrawGizmosSelected()
  12. {
  13. }
  14. private void DrawShexian()
  15. {
  16. Gizmos.color = Color.red;
  17. var direction = transform.TransformDirection(Vector3.forward) * 5; // 在物体的前方绘制一个5米长的线
  18. Gizmos.DrawRay(transform.position, direction);
  19. Gizmos.color = Color.blue;
  20. var d = transform.TransformDirection(Vector3.right) * 5; // 在物体的前方绘制一个5米长的线
  21. Gizmos.DrawRay(transform.position, d);
  22. }
  23. }