var TargetX = inventoryWindow2.x-45;//inventory rectx
var TargetY = inventoryWindow2.y-55;//inventory recty
GUI.DrawTexture(Rect(TargetX+30,TargetY+30,150,150), inventoryTex, ScaleMode.StretchToFill, true, 0);//inventory picture
if (GUI.Button(Rect(item1Inv.x + inventoryWindow2.x,item1Inv.y + inventoryWindow2.y, 40,40),GUIContent (texture1)) && item1GUI == 0){
//the button i want to follow the inventory, but also be where ever i clicked, //item1Inv.x and .y are what are edited and inventorywindow2 is what it follows
if (example == GameObject.Find("example")) {
var u = (Input.mousePosition.x);
var v = (Input.mousePosition.y);
item1Inv.x = u;//makes it equal to mouse positions,
item1Inv.y = v;//
}
//everything works but im not calculating right, ive tried u = mouseposition.x-invetorywindow2.x and many other ways, but none have worked yet to be at the exact mouse position, any ideas would be appreciated!
GUI coordinates and screen coordinates are different. GUI coordinates start in the upper left of the screen. Input.mousePosition (screen coordinates) start in the lower left of the screen. Since all your code above has to be in OnGUI(), you should use Event.current.mousePosition inside of OnGUI(). That mouse position is in GUI coordiantes.