Search Unity

Dynamically Resizing Selection Box

Discussion in 'UGUI & TextMesh Pro' started by BindingForceDev, Mar 25, 2015.

  1. BindingForceDev

    BindingForceDev

    Joined:
    Aug 13, 2014
    Posts:
    40
    So basically, I am working on building the in-game menu for my RPG, but I am having a time figuring out how to show which menu elements are selected. Basically, my script keeps track of which objects are selectable and moves a prefab around that has a selection box outline image component. I'd like to have the prefab dynamically resize to match the current object selected. All of this is happening on my menu canvas object. My intuition tells me I have to manipulate the rect transform width/height, but then again I'm really not sure where to begin to find the right values to generate. Any ideas or suggestions are most welcome!!! I have done a lot of searching for any similar problems but I've come up dry, so my apologies if this is old hash.

    Happy coding!
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If you make the selection box a child of the selected object, and set its anchors to stretch, then it will change its size and aspect ratio automatically based on the parent.
     
  3. BindingForceDev

    BindingForceDev

    Joined:
    Aug 13, 2014
    Posts:
    40
    Thanks Antistone, this is the perfect solution! One thing I noticed though, if the new parent has scale values other than 1, the scale of the selection prefab seems to be automatically affected (and I'm interested in why if anyone knows...). Anyway, it is simply fixed by resetting the prefab scale attributes to 1 though.