Search Unity

How to anchor click triggers when screen size could change

Discussion in '2D' started by wgpalexander, Dec 17, 2017.

  1. wgpalexander

    wgpalexander

    Joined:
    Feb 7, 2017
    Posts:
    2
    Hi guys

    I am sure this is a simple question to help with, but I haven't found a clear way to do this yet.

    I have designed a simple game that has a row of buttons at the bottom of the screen. Each button is a parent game object with 2 graphics as children objects (one for when the action is available, one for when not available).

    In addition to these I have a Canvas element with click triggers, on click these run their respective scripts which I have no problems with just now.

    My issue is that if I resize my window / game screen then the click triggers go out of alignment. Is there a method or approach I can use to somehow tie the click triggers to their location & size them dynamically?

    Thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yes, you just need to anchor them appropriately to their parent RectTransforms.

    All this is covered in the UI tutorials, which you really should go through if you haven't already.
     
  3. wgpalexander

    wgpalexander

    Joined:
    Feb 7, 2017
    Posts:
    2
    Hi JoeStrout, thanks for the pointers. I haven't been through those particular UI tutorials so that is where I'll start.

    For what it's worth, I am using RectTransform at the moment but the way I'm setting it up it clearly isn't working as intended.