- Home /
 
               Question by 
               DoctorNotropis · Dec 27, 2017 at 01:47 PM · 
                mouse-dragdrag objectsc #  
              
 
              How to manage multiple objects in a click and drag scrip?
I have a script to click and drag objects (tiles) around the screen. It worked fine when applied to a single object, but I need to manage multiple tiles, so i tried to modify the script and put it on an empty game object and assign the variables there.
 public Vector2 vctBellTilePosition = new Vector2(-5, -4);
 public Vector2 vctBellTilePosition2 = new Vector2(-5, 0);
 public Vector2 vctScreenpoint;
 public Vector2 vctOffset;
 public GameObject gmoBellTile;
 public GameObject gmoBellTile2;
 void Start()
 {
     gmoBellTile.transform.position = vctBellTilePosition;
     gmoBellTile2.transform.position = vctBellTilePosition2;
 }
 void OnMouseDrag()
 {
     Vector2 mousePosition = new Vector2(Mathf.Round(Input.mousePosition.x / 30) * 30, Mathf.Round(Input.mousePosition.y / 30) * 30);
     Vector2 objPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     gmoBellTile.transform.position = objPosition;
 }
Here's the relevant code. At the moment, the tiles go to their start point just fine, but I can't get them to move. Any help would be greatly appreciated.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Dragging an Object with mouse in 2D 1 Answer
Trajectory on mouse up 0 Answers
How to deal with collision by using mouse drag? 0 Answers
How to move object with mouse at same rate of mouse - 2D 1 Answer
Move Camera once Mouse Drag is complete 2 Answers
