How to match two GUITexture together and draw a line

  1. Hello all, as shown in the picture, i would like to ask how could I match the pair and draw a line from there? The game flow like this : Player have to click on the cloud (guiTexture) to match the one on the right, so after matching, if it is valid, a line will be draw else no line is draw.
  1. Next would like to ask how to reshuffle/randomize the position of the guiText after some interval of times. For example, i have a set of guiTexts with fixed position on the scene, so like for example after 20seconds, i want all the guiText to change their current position to a new position. How do i go about doing it?? Thank you

Search the forums, there are many ways to draw a line between two points in Unity and this has been answered in the last 24 hours (not to mention many times in the past).

Hi JohnnyA, i did try to search in the forum before asking the question, maybe i have missed out something. I manage to find something to draw the line. But however the code start at the middle of the scene and it does not stop drawing the line when the mouse is clicked.

var linePoints : Vector2[];
var lineColor = Color.white;
var lineDrawOn = false;
private var lineMaterial : Material;

function Awake () 
{
	lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
		"SubShader { Pass {" +
		"	BindChannels { Bind \"Color\",color }" +
		"	Blend SrcAlpha OneMinusSrcAlpha" +
		"	ZWrite Off Cull Off Fog { Mode Off }" +
		"} } }");
	lineMaterial.hideFlags = HideFlags.HideAndDontSave;
	lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}

function OnPostRender () 
{
	if (!lineDrawOn || linePoints.Length < 2) {return;}
	
	var cam = camera;
	var nearClip = cam.nearClipPlane+.01;
	lineMaterial.SetPass(0);
	GL.Begin(GL.LINES);
	GL.Color(lineColor);
	var end = linePoints.Length-1;
	for (i = 0; i < end; i++) {
		var v = cam.ViewportToWorldPoint(Vector3(linePoints[i].x, linePoints[i].y, nearClip));
		GL.Vertex3(v.x, v.y, v.z);
		v = cam.ViewportToWorldPoint(Vector3(linePoints[i+1].x, linePoints[i+1].y, nearClip));
		GL.Vertex3(v.x, v.y, v.z);
	}
	GL.End();
}

@script RequireComponent(Camera)

function Start () 
{
	linePoints = new Vector2[2];
	linePoints[0] = Vector2(.5, .5);
	lineDrawOn = true;
}

function Update () 
{
	var m = Input.mousePosition;
	linePoints[1] = Vector2(m.x/Screen.width, m.y/Screen.height);
}

bump… please help :frowning: