- Home /
How I can see that ray from Debug.DrawRay ?
Hi, I just stopped at the OnCollisionEnter event and found an example like this:
void OnCollisionEnter(Collision hit){
foreach (ContactPoint contact in hit.contacts) {
Debug.DrawRay(contact.point, contact.normal, Color.red);
}
}
I tried but...how I can see that red ray ?
Thanks
Update: according to advise from SGamerXxX I modified the code and get the result I want thanks alot:
Debug.DrawRay(contact.point, contact.normal, Color.red, 20, true);
Not sure if this would work, but try turning on gizmos ( Game Window ( $$anonymous$$aximize on Play,Stats,Gizmos))
I THIN$$anonymous$$ you need to call it within update()
the ray is being drawn and disappearing so fast you never see it.
You don't need Update if you add a duration. Turning on gizmos does indeed allow it to be seen in the game view.
@SGamerXxX yes that did it !! many thanks my friend. posted as an answer to check it plz
Thanks for all other replay and help
Answer by SGamerXxX · Aug 20, 2012 at 08:40 PM
Good it worked, here is it an answer form as you requested:
Try turning on gizmos ( Game Window ( Maximize on Play,Stats,Gizmos))
You must use both... turn gizmos on AND put the third/fourth parameters as well.... gl
Answer by Muuskii · Aug 20, 2012 at 03:40 AM
Well, let me ask you this: Are you looking in scene view? Because that's the only place where it's visible. If you are and you STILL can't see it, first add Debug.Log("Collision"); to make sure the collision is ACTUALLY going off, secondly add a duration to the ray so that it doesn't disappear so fast:
Debug.DrawRay(contact.point, contact.normal, Color.red, 5.0f);
If you still can't see it and the Gizmos thing doesn't work out. . . I might have to come over to your house ;)
I've been looking all over for this answer and clicking on scene view was it! I'd +1 you but I cant because I only have 1 rep. haha aww :(
$$anonymous$$ake sure that you are actually Raycasting first and then running your debug piece of code: Debug.DrawRay(contact.point, contact.normal, Color.red, 5.0f);
In my case, I was declaring the Ray and just after was trying to run this Debugging before my raycasting actually happened.
Obviously but still...
So the ultimate recipe is: - Run Debug.DrawRay after raycasting is happened - Turn on Gizmo - Add DrawRay duration
Result: Ray visible as in Scene, as in Game view
Your answer
![](https://koobas.hobune.stream/wayback/20220613075913im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Always play music? 1 Answer
0xFEFF error im new PLEASSE help. Script error 1 Answer
Instantiate cloned prefab to local position of an empty object 1 Answer
Using a string in a C# script in a .js 1 Answer
Zombie Spawner script 2 Answers