Home Forums Unity SDK 2D homemade GazeAware component Reply To: 2D homemade GazeAware component

#11254
Alex [Tobii]
Participant

Hi @gregorm, you can try something like this:


			Vector3[] corners = new Vector3[4];
			Button.GetComponent<RectTransform>().GetWorldCorners(corners);
			var x1 = float.MaxValue;
			var x2 = float.MinValue;
			var y1 = float.MaxValue;
			var y2 = float.MinValue;
			foreach (Vector3 corner in corners)
			{
				var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.current, corner);
				if (screenPoint.x < x1)
				{
					x1 = screenPoint.x;
				}

				if (screenPoint.x > x2)
				{
					x2 = screenPoint.x;
				}

				if (screenPoint.y < y1)
				{
					y1 = screenPoint.y;
				}

				if (screenPoint.y > y2)
				{
					y2 = screenPoint.y;
				}
			}

			var rect = new Rect(x1, Screen.height - y2, x2 - x1, y2 - y1);