I know there exist some functions like lineRenderer etc, but I want to create a straight line in the scene using two points(in Vector3 form). I don't want to draw the line by using any key or using the mouse, I just want to see the line in the scene when I trigger some event or just after I click play button.
Can anyone help me?
//For creating line renderer object
lineRenderer = new GameObject("Line").AddComponent<LineRenderer>();
lineRenderer.startColor = Color.black;
lineRenderer.endColor = Color.black;
lineRenderer.startWidth = 0.01f;
lineRenderer.endWidth = 0.01f;
lineRenderer.positionCount = 2;
lineRenderer.useWorldSpace = true;
//For drawing line in the world space, provide the x,y,z values
lineRenderer.SetPosition(0, new Vector3(x,y,z)); //x,y and z position of the starting point of the line
lineRenderer.SetPosition(1, new Vector3(x,y,z)); //x,y and z position of the end point of the line
Ok, I've figured it out by using LineRenderer like this:
var line: GameObject=GameObject.Find("/LineRenderer");
fence = Instantiate(line,Pos,Rotation);
fence.setPosition(0,p1);
fence.setPosition(1,p2);
Thanks for all of your answers above
If you want a line in 3D space, try creating a LineRenderer, sample here: http://rockonflash.wordpress.com/2010/04/17/how-to-do-lasers-in-unity3d/
docs here: http://docs.unity3d.com/Documentation//Components/class-LineRenderer.html
For a 2D line (onGUI), try:
function OnGUI () {
GUIUtility.ScaleAroundPivot (Vector2(0.5, 0.5), Vector2(328.0, 328.0));
GUI.Label (Rect (200, 200, 256, 256), textureToDisplay);
}
there are other options presented in this discussion: http://forum.unity3d.com/threads/17066-How-to-draw-a-GUI-2D-quot-line-quot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With