Drawn line collision

Hi,I have a problem with my line.I can draw line on screen but I want to make collision detection with cube.How can I do that?OnTriggerEnter not working in this case.

This is my draw line code.
#pragma strict
var pos1 : Vector3; var pos2 : Vector3; var objectHeight = 2.0;

function Update ()
{

if (Input.GetMouseButtonDown(0)) {
pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos1 = Camera.main.ScreenToWorldPoint(pos1);
pos2 = pos1;
}
if (Input.GetMouseButton(0)) {
pos2 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos2 = Camera.main.ScreenToWorldPoint(pos2);
}
if (pos2 != pos1) {
var v3 = pos2 - pos1;
transform.position = pos1 + (v3) / 2.0;
transform.localScale.y = v3.magnitude/objectHeight;
transform.rotation = Quaternion.FromToRotation(Vector3.up, v3);
}

}

function OnTriggerEnter(carpisma : Collider)
{
if(carpisma.tag==“Kup”)
{
Debug.Log(“Collision”);
}
}

You could define a BoxCollider for your cube, and then call RayCast on it to see whether your line (ray) intersects that box.

Thanks for your reply,Do I need to Raycast codes on cube or line?Im a bit confused

You call it on the BoxCollider, passing in a Ray that represents your line. There is an example here. That uses a ray based on the mouse position, but start with that and then see if you can modify it to represent the line you’re already drawing.