Question by 
               Montreal · Jan 06, 2018 at 09:31 PM · 
                drageventeventsystemdragging  
              
 
              How to stop object from going to center of mouse when dragging starts
I have a script for dragging my object up and down, but the object always centers itself onto the mouse when i initiate a drag. How can I make it stay in place regardless where I initiate the drag? Please I need help with this, i cant figure it out.. how do i implement offset?
 using UnityEngine;
 using UnityEngine.EventSystems;
 public class DragMapScript : MonoBehaviour, IDragHandler, IEndDragHandler
 {
 bool pressed;
 public void OnDrag(PointerEventData pad)
 {
     pressed = true;
 } 
 public void OnEndDrag(PointerEventData pad)
 {
     pressed = false;
 } 
 void Update()
 {
     if (pressed)
     { 
     Vector2 pos = Input.mousePosition;
     pos.x = transform.position.x;
     pos.y = Mathf.Clamp(pos.y, 90, 347);
     transform.position = pos;
     }
 }
}
please help.. i am desperate cant find any solution
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
So i want this problem with ui buttons done 1 Answer
How Can I Get An Event To Do It's Original Base Action As Well As My Code 1 Answer
Adding EventTrigger.Entry to EventTrigger component via script doesn't update component's editor UI 0 Answers
OnDrag is moving all colliders on Touch? (Not on Standalone) 0 Answers
EventSystem.current is returning null 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                