c# - Constraining X and Y Draggable Area -
i'm trying limit draggable area objects on screen , i'm getting few errors in code - trying keep simple now, reset the max x or y if object gets dragged beyond limits, i'm still not having success. use understanding how this.
float maxdragx = 1000; float maxdragy = 700; vector3 mouseposition = new vector3(eventdata.position.x, eventdata.position.y, distance); transform.position = mouseposition; // set object coordinates mouse coordinates if(transform.parent.gameobject == partspanel) { transform.setparent(draglayer.transform); // pop object draglayer move object out of partspanel } if(transform.parent.gameobject == buildboard) { // constrain drag boundaries of buildboard code if(transform.position.x >= maxdragx) transform.position.x = new vector3(maxdragx, mouseposition.y, distance); if(transform.position.y >= maxdragy) transform.position.y = new vector3(mouseposition.x, maxdragy, distance); }
you cant set vector position.x or position.y float just. have change position completely
float maxdragx = 1000; float maxdragy = 700; vector3 mouseposition = new vector3(eventdata.position.x, eventdata.position.y, distance); transform.position = mouseposition; // set object coordinates mouse coordinates if(transform.parent.gameobject == partspanel) { transform.setparent(draglayer.transform); // pop object draglayer move object out of partspanel } if(transform.parent.gameobject == buildboard) { // constrain drag boundaries of buildboard code if(transform.position.x >= maxdragx) transform.position = new vector3(maxdragx, mouseposition.y, distance); if(transform.position.y >= maxdragy) transform.position = new vector3(mouseposition.x, maxdragy, distance); }
Comments
Post a Comment