- Home /
Drag and Drop for X and Z
good day,
so i want to play around with drag and drop on a 3D game, but i dont want to drag it in the X,Y direction, i want to drag it on X,Z positions. like i have a playground and i want to drag it only on this specific "plane".
so i used this script from a tutorial:
 private Vector3 mOffset;
 
 private float mYCoord;
 
 private void OnMouseDown()
 {
     mYCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
 
     mOffset = gameObject.transform.position - GetMouseWorldPos();
 }
 
 Vector3 GetMouseWorldPos()
 {
     Vector3 mousePoint = Input.mousePosition;
 
     mousePoint.z = mYCoord;
 
     return Camera.main.ScreenToWorldPoint(mousePoint);
 }
 
 private void OnMouseDrag()
 {
     transform.position = GetMouseWorldPos() + mOffset;
 }
the problem is, he is fixing the z coord. when i change it to Y, i cant even click on my gameobject, when i change it back to Z i can click my gameobject again... is it some vector2D only stuff or something?
so my question is: how do i change the code to make it work with the X,Z coords instead X,Y coords?
Your answer
 
 
             Follow this Question
Related Questions
OnBeginDrag, OnEndDrag not being called for unknown reasons 1 Answer
Drag and Drop w/ Snapping 0 Answers
Drag-and-drop gameObject inversely proportional to mouse speed? 0 Answers
Drag Item Scaling on Phone 0 Answers
Where can I find resources on how to drag 3D objects into a room based on a grid 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                