Search Unity

Unity 2D: Scaling objects/sprites problem.

Discussion in 'General Graphics' started by Mystique5, Jun 21, 2017.

  1. Mystique5

    Mystique5

    Joined:
    Aug 22, 2015
    Posts:
    8
    upload_2017-6-21_17-33-48.png
    this above is my game. The dark blue box is a room where my player can move around. I want my room to shrink using a script. (vertically/horizontally or both at same time)
    The problem is..
    my room is made up of 4 sprites with box colliders attached:
    upload_2017-6-21_17-34-50.png
    I could try to rescale the parent (room) but then this happens..
    upload_2017-6-21_17-36-13.png
    The horizontal lines become squashed to the point they become invisible. I want it to retain it's previous length.

    upload_2017-6-21_17-38-20.png
    if I select both vertical lines and shrink them. The thickness of each line is maintained. But the horizontal lines do not make contact with the vertical lines as I did not reposition it. Is there any way to get a script for the room to shrink vertically whilst letting the two horizontal lines reposition themselves automatically?
     
  2. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    One way to go about it is to manually set the global scale of lines after you scale the room parent. You can keep the X scale for horizontal lines, but reset the Y scale constantly. Likewise keep the Y scale for vertical lines, but reset the X scale. That way the walls will keep coming closer and closer to each other while maintaining their original width. This approach will not work if you plan to have walls that aren't perfectly aligned with X or Y axis though. Also I'm not entirely sure, but if your walls have colliders it might be a good idea to put them on separate layers so they dont freak out when pushed into eachother.