Debug.DrawRay Tutorial

I’ve checked this: Debug.DrawRay and it’s really not helping me alot. I just need a bit of understanding of how this works and I’ll be fine! I have this script

var ray : Ray = Camera.main.ScreenPointToRay(Vector3 (Screen.width * 0.5, Screen.height * 0.5, 0));
		Debug.DrawRay (?, ?, Color.red);

It says to put transform.position and then a forward variable where my ? are. I’m not sure what to do in this situation, do I put my ray variable there or something? I know how to use Physics.Raycast but not Debug.Ray because it’s different but I’m sure I’ll quickly get it if you tell me! Thank you!

I think you want this:

Debug.DrawRay(ray.origin, ray.direction * rayCastDistance);

Note that for what you are doing here is the same as:

Debug.DrawRay(camera.main.transform.position, camera.main.transform.forward * rayCastDistance);

The only difference is that your ‘ray’ will start at the near clip plane instead of at the camera position. Note ‘rayCastDistance’ is either constant you provide or a variable you define and initialize.