DrawLine doesn't work like in the textbook

Hi guys, I’m trying to follow up on a C# Unity textbook I’m reading. It said that if I use this script on the main camera

using UnityEngine;
using System.Collections;
public class ReturnZombie : MonoBehaviour
{
    //Use this for initialization
    void Start ()
    {
    }
    //Update is called once per frame
    void Update ()
    {
        Debug.DrawLine(transform.position,
                       GetZombie().transform.position);
    }
    //returns a zombie
    Zombie GetZombie()
    {
        return (Zombie)GameObject.FindObjectOfType(typeof(Zombie));
    }
}

And created a gameobject with a zombie class attached to it, I’d see a line drawn between the object and the camera in scene view. Well, I don’t see it. :frowning:

This is the screenshot the textbook attached that I’m supposed to see:

What am I doing wrong?

I guess you actually see the line but only for one frame… check the docs. try to set the next two parameters as well…

What docs? What parameters?
It’s supposed to be in scene view, so not only for “one frame”. Look at the screenshot from the textbook.

Look here: Unity - Scripting API:
if you want the line to be permanent, use Gizmos.DrawLine() instead and call it in OnDrawGizmos() instead of Update().

Don’t forget to enable Gizmos in your game view.

Many thanks! :slight_smile:

Update is only called during game mode, if you are expecting to see it in scene view during EDIT MODE then you can use gizmos

1 Like