How to create a circle that follows your cursor without using GUItexture.

Ok so in my 2D platformer the user will be able to create a circle that will follow the cursor by pressing a certain key. And then he will be able to place this circle on the level by clicking on the left mouse button. I have achieved my result, by having a circle GUItexture. But my problem is that the circle is placed on the screen (Since GUItexture positioning is between 0 and 1, one end of the screen to the other) and not on my level. So when I move left and right the circle moves along. I need the circle to remain in the position I selected.

Any help is appreciated.
Thank you.

1 Answer

1

The code below should get you started. It is attached to a game object in the scene, so you’ll have to make a circle graphic and attach it to a plane. Note the ‘z’ value in mousePos.z is the distance from the camera.

function Update (){
	if (Input.GetMouseButton(0)) {
		var mousePos = Input.mousePosition;
		mousePos.z = 5.0f;
		transform.position = Camera.main.ScreenToWorldPoint(mousePos);
		
	}
}

Thank you so much for your reply, It worked like a charm :).

–