how to draw lines between two gameobjects ?

hey

i want to draw a line between a two gameobject using line render , i have tried something called gizmoz and i draw a line using this code

Gizmos.DrawLine(transform.position,new Vector3(-45.49318f,11.54467f,-69.10096f));

but i need the line to be drawn in run time whether in line render or something else ?

I dunno about all that gizmo stuff, and whatnot -

buttt you could always just use a raycast from one object to the other - not sure how you were going to use that? - but then you could use a debug code to tell it to draw a line (just a simple one pixel line is all I know) along the rays path. I sure couldn’t tell you how to code that :frowning:

thnx for the reply

but can give me an example that Describes your idea

1 Like
function Update () {
    var forward : Vector3 = transform.TransformDirection(Vector3.forward) * 10;
    Debug.DrawRay (transform.position, forward, Color.green);
}

But this only works in game, if you want editor.

Then check the Gizmo.Drawline

var target : Transform;
function OnDrawGizmosSelected () {
    if(target != null) {
        // Draws a blue line from this transform to the target
        Gizmos.color = Color.blue;
        Gizmos.DrawLine (transform.position, target.position);
    }
}

And click the object when you want to see the linie.

2 Likes

thnx snortop

but i know how to do it in Gizmoz , i need a way to draw the line not in the scene but in the game it self

Can use LineRenderer…

1 Like

thnx mgear ,

i succeed in draw a line start from one of my game objects but the line go down not straight , i need the line to be gone from one object to another also in line render , how?

black6,

I recently got started playing with unity and had a similar need. I ended up using this:

lineRenderer.SetPosition(0, new Vector3(objectOne.transform.position.x,objectOne.transform.position.y,objectOne.transform.position.z));
lineRenderer.SetPosition(1, new Vector3(objectTwo.transform.position.x,objectTwo.transform.position.y,objectTwo.transform.position.z));

Hope that helps.

Did you try that ^Heidgerkens code:
LineRenderer.SetPosition(0, transform.position);
LineRenderer.SetPosition(1, target.position);

1 Like

thnx a lot Heidgerken that was help , thnx mgear too ,

i succeed draw the line between the two objects but there is a line keep going down ?

You can also use GL.line.

ok guys i have another question,

if i draw a line between three objects (LineRenderer) and i want to delete one of them not the whole line , can i do it? , how?

Anybody have answer for just above question :!:

It’s easier and more flexible to do anything with line-drawing by using Vectrosity.

–Eric

1 Like

This asset is very good. Thanks!!