Search Unity

[SOLVED] How to Visualize Raycast2D?

Discussion in 'Physics' started by ChrisIsAwesome, Jun 3, 2017.

  1. ChrisIsAwesome

    ChrisIsAwesome

    Joined:
    Mar 18, 2017
    Posts:
    184
    Not sure if I should put this under Scripting or Physics, but here it goes:

    I'm having an issue with my raycasting and would like to visualize it to debug it. How would I go about this?

    Any help would be greatly appreciated!

    -- Chris
     
  2. StrawberryJellyfish

    StrawberryJellyfish

    Joined:
    Oct 29, 2016
    Posts:
    23
  3. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    Yes as the link Lumberjack72 posted says you can use Debug.DrawRay() for example like this to display the ray for 10 seconds:
    Debug.DrawRay(ray.origin, ray.direction, Color.red, 10.0f);

    Then you need to enable Gizmos in the editor to see it.
     
    ber3232, melisomnia, hms0589 and 2 others like this.