I use them for looking at what enemies are looking or aiming at. Since it's Debug it only shows up in the scene view and not in your actual game play. They can be very useful sometimes. Here's an example of what they look like. The red lines are the debug rays.
How I'm doing it:
Debug.DrawRay (transform.position, Vector3.forward*100 , Color.red);
So debug is a class that contains that governs all the debugging functions.
DrawRay is the function we want to draw the line.
Then the next part of the code goes like:
(Position of where the ray will start which is a Vector3, direction of ray and how long, and then the color of it)
For the direction of a ray it can go 6 ways. (up, down, left, right, forward, backward)
Vector3.forward is just shortcut instead of saying Vector3(0,0,1)
And for those who aren't familiar with Vector3, its just 3 coordinates to define a object in 3d space. It goes (x position, y position, z position). x is left and right. y is up and down, and z is forward and backward.
Colors you can either make by using the class variables or by using one of it's predefined colors. In the colors class, it's predefined variables are : red, green, blue, white, black, yellow, cyan, magenta, grey, and clear. Read more on the colors class here.
How I'm doing it:
Debug.DrawRay (transform.position, Vector3.forward*100 , Color.red);
So debug is a class that contains that governs all the debugging functions.
DrawRay is the function we want to draw the line.
Then the next part of the code goes like:
(Position of where the ray will start which is a Vector3, direction of ray and how long, and then the color of it)
For the direction of a ray it can go 6 ways. (up, down, left, right, forward, backward)
Vector3.forward is just shortcut instead of saying Vector3(0,0,1)
And for those who aren't familiar with Vector3, its just 3 coordinates to define a object in 3d space. It goes (x position, y position, z position). x is left and right. y is up and down, and z is forward and backward.
Colors you can either make by using the class variables or by using one of it's predefined colors. In the colors class, it's predefined variables are : red, green, blue, white, black, yellow, cyan, magenta, grey, and clear. Read more on the colors class here.
Comments
Post a Comment