Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: RandomGuy on January 09, 2013, 07:03:12 AM

Title: Getting UI Dragable to snap to grid(like)
Post by: RandomGuy on January 09, 2013, 07:03:12 AM
Is their anyway to get the UI Dragable script to get objects to snap to like a grid, and if I could make a grid that turns off and on that would be great to .
Title: Re: Getting UI Dragable to snap to grid(like)
Post by: dlewis on January 09, 2013, 07:46:48 AM
Have you seen the CenterOnChild sscript? It's used in one of the examples.
Title: Re: Getting UI Dragable to snap to grid(like)
Post by: RandomGuy on January 12, 2013, 12:16:03 PM
Just made my own script , call it whenever you need to snap to a solid 10 divisible number
  1.         public  void SnapIT ()
  2.         {
  3.                
  4.                 //Math.Round(3.44, 1); //Returns 3.4. // its not that C# is better, but the documentation deffinitly is .
  5.                
  6. Vector3 Temp = this.transform.localPosition ;
  7.         float tempX = Mathf.Round(Temp.x/ 10) ;
  8.         float tempY = Mathf.Round(Temp.y/10) ;
  9.         float tempZ = Mathf.Round(Temp.z/10) ;
  10.          NewPos = new Vector3(tempX *10 , tempY*10,tempZ*10 ) ;
  11.                 this.transform.localPosition = NewPos ;
  12.                
  13.         }
  14.