- Home /
An UI element will follow the mouse and snap to a grid, but why is the grid shifted after every game start?
If I click on an UI element, the element will follow the mouse and snap to a grid. I use this to arrange the elements ("talent tree").
 void Update()
 {
         if(isDragging)
         {
             Vector3 pos = Input.mousePosition;
             pos.x = Mathf.Round(pos.x / 30.0F) * 30.0F;
             pos.y = Mathf.Round(pos.y / 30.0F) * 30.0F;
             transform.position = pos;
         }
 }
The Problem: If I arrange and save the element positions in play mode (sure, I restore the positions in editor mode) and I start play mode again, the grid is always slightly shifted. It seems the mouse have after every start a slightly different position. Is this possible?!

 
                 
                talent-snap.jpg 
                (62.4 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Sprite Snap and Follow Mouse 0 Answers
How to drag gameobject (only x y) snapped to a grid? 2 Answers
Gizmo won't stop snapping to grid. 1 Answer
Snap object to grid with offset? 1 Answer
RTS building snap to grid 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                