Draw line on circle as score meter

hello

I’m trying to draw a line on my circle to show the score for a kids game. I got the center of the circle(startPosition) and the point on the circle where it is supposed to draw to (endPosition).

I’ve tried everything but the line won’t draw.

could someone help me out ?!

void DrawLine()
	{
		GameObject scriptMain =  GameObject.Find("Main Camera");
		ScreenResolution scr = (ScreenResolution)scriptMain.GetComponent("ScreenResolution");
		rectangle = scr.e;
		
		float xCenter = rectangle.width / 2;
		float yCenter = rectangle.height / 2;
		
		float Radius =  Vector2.Distance(new Vector2(xCenter, yCenter),new Vector2(xCenter,rectangle.height));
			
		Vector2 StartPosition = new Vector2(xCenter,yCenter);
		Vector2 EndPosition = new Vector2(Radius * Mathf.Cos(Mathf.PI/2-1),Radius * Mathf.Sin(Mathf.PI/2 - 1));
		
		
		Debug.DrawLine(StartPosition,EndPosition, Color.red);
	}

1246747--53595--$Schermafbeelding 2013-05-16 om 13.05.29.png

Does it draw in the editor?

I would look up line renderer.

LineRenderer has some limitations. Like you cannot attach more then 1 LineRenderer to a GameObject, for example. You can of course dynamically create a GameObject with the LineRenderer from a prefab and setup LineRenderer appropriately for that instance (points + materials). Also, your game looks like 2D. Not sure if LineRenderer is appropriate here. If it is 2D are you using any of the 2D packages like Orthello?

I am building a 2D game. I just started to use lineRender for a laser. I find it works well in terms of being able to set the two positions of the laser (start and end) gun nozzle, enemy hit point. What would you suggest as an alternative @cdevl? And why?

The reason LineRenderer does not seem like a natural solution here because it is a 3D artifact. You would need to do some additional calculations with camera to position it correctly (unless your game is “pseudo 2d”; with fixed view from above into a fixed plane). Unfortunately, looking around it does seems like LineRenderer would be the best “free” solution. I didn’t realize that free version of Orthello did not include line drawing. The paid add-on does :). If you have a paid version of Unity (I don’t) you can try this:

http://wiki.unity3d.com/index.php?title=VectorLine

Here is an older interesting discussion thread on this topic:

http://forum.unity3d.com/threads/17066-How-to-draw-a-GUI-2D-quot-line-quot