Scrollview with Input.MousePosition?

How do you make the Input.MousePosition fit with a GUI.ScrollView? Right now the drag/drop system does not work in my game, I found the problem, but I cannot seem to find a solution. I just can’t. The problem is that the Input.MousePosition does not work with GUI group things(even worse with scrollviews). So how would I fix this? P.S: InputManagerClass.mousePosition is just a getter with Input.MousePosition.x, and Input.MousePosition.y - Screen.height.

Thanks in advance!


private void RenderInventory(int id){
		//GUI.BeginGroup (inventoryWindow);
		ScrollPosition = GUI.BeginScrollView (new Rect (inventoryWindow.x + 0,inventoryWindow.y + 19,395,225), ScrollPosition, new Rect (0,0,370,1161));//Scrollfield.
		int cnt = 0;//Location of the current item in loops.
		for(int y = 0; y < inventoryCols; y++){//Y
			for(int x = 0; x < inventoryRows; x++){//X
				if(cnt < myItems.Count){//If the item exists.
					if(myItems[cnt].itname != null && myItems[cnt].itname.Length > 1){//If not null/bugged.
						Rect rect = new Rect(3+x * 46.5f,y * 46.5f,45,45);
						GUI.Label(rect,"" + myItems[cnt].itname,inventoryButton);

						if (rect.Contains(InputManagerClass.mousePosition))
							Debug.Log("Contains MOUSE!!!");
							if (Event.current.type == EventType.MouseDown)

						//if(Event.current.type == EventType.MouseUp && currentDrag != null){
						//	OnCurrentDragDrop(myItems[cnt]);

					//If bugged/null.
						//If this is null/bugged, Remove.
				//If does not exist.
					GUI.Label(new Rect(3+x * 46.5f,y * 46.5f,45,45),"",inventoryButton);
				//Increase the current loop item.
		GUI.EndScrollView ();//End the scrollfield
		//GUI.EndGroup ();

If you want to use coordinates of a mouse in the OnGUI function, you shall use Event.current.mousePosition, instead of Input.mousePosition. But don’t forget that Event.current will be bound on coordinates to BeginGroup or to Scroll. I.e. for computation of a real line item it will be necessary to add still coordinates of the upper left corner of the container if, of course, it is.