CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Dec 2021
    Posts
    2

    Set to coordinates to centre of grid

    I have these buttons created in unity- 27 by 27 which has 9 by 9 subgrids Each button is 10 by 15 pixels. I want to get the coordinates of the centre of each subgrid(which has no grouping) which are numbered 1 to 9. There must be a neater way than coding

    Code:
    private int _num
    private int devy
    private int devx
    private float _Xcood
    private float  _Ycood
    
    if (_num==1 OR _num==2 OR _num==3)
        { devy =1}
    else if  (_num==4 OR _num==5 OR _num==6)
        {devy=0}
    else if   (_num==7 OR _num==8 OR _num==9)
        {devy=-1}
    
    if (_num==3 OR _num==6 OR _num==9)
        { devx =1}
    else if  (_num==2 OR _num==5 OR _num==8)
        {devx=0}
    else if   (_num==1 OR _num==4 OR _num==7)
        {devx=-1}
    
    _Xcood=devx*10+position.y
    _Ycood=dexv*15+position.x
    Last edited by 2kaud; January 1st, 2022 at 05:30 AM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured