- Home /
Debug.DrawRay not drawing Ray
I went through multiple posts trying to find the answer for this, but nothing has worked.
I attached a script with this Update method
void Update () {
RaycastHit hit;
Ray putterRay = new Ray (transform.position, Vector3.left);
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 10, Color.green, 30, false);
}
To my object that I want a ray drawn from. Nothing shows. I am looking in scene view and all other gizmos appear to be showing.
(Also I know my actual ray is different from the drawn ray; at the moment I am just trying to get the drawn ray to work so I know precisely where to position it on my object.)
I'm fiddling around on a completely new project and scene just to test this out-- apparently the ray only gets drawn in Game $$anonymous$$ode with gizmos on but not on the Scene view. Does anyone know why this could be?
Answer by LeonmFF · Apr 26, 2018 at 03:15 PM
The problem is your direction. In your script, add a public Transform mDir; Create another GameObject. and in the inspector of your gameObject that have your script, assign your new gameobject to the mDir variable. You will see your ray (scene mode, not game) going to you new GameObject.
$$anonymous$$g
public class DebugDrawRayTeste : $$anonymous$$onoBehaviour {
public Transform finalPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit hit;
Ray putterRay = new Ray(transform.position, Vector3.left);
Debug.DrawRay(transform.position, finalPos.position, Color.green, 300, false);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612161522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
DrawRay not drawing a ray 1 Answer
Raycast doesn't work properly? 0 Answers
Make Ray visible 2 Answers
Debug Draw for BoxCast and CapsuleCast 0 Answers
Problem With Physics.Raycast 1 Answer