- Home /
Why does my UI panel resize?
Unit symbols appear on a set of UI panels as per the code below. However, the first one becomes wide, like in the attached screenshot, once the sprites are inserted by the code. The UI panels are controlled by a Horizontal Layout Group and are all the same (all are duplicates of the first one). There is no difference in the sprites either - the same sprite is used by the wide panel (#1) and narrow panel #4. When I changed the sprite in the wide panel in the inspector to another sprite, the panel remained wide. When I changed the sprite in one of the narrow panels in the inspector, that panel became wide as well. What do I need to do to resolve this issue?
for (int i = 0; i < gameController.GetComponent<GameController>().unitsInGroup.Count; i++)
{
playerUnitSlots[i].GetComponent<Image>().color = occupiedSpaceColor;
playerUnitSlots[i].GetComponent<Image>().sprite = gameController.GetComponent<GameController>().unitsInGroup[i].GetComponent<PlayerHealth>().unitImage;
}
[1]: /storage/temp/181865-imagesresize.jpg
Your answer

Follow this Question
Related Questions
Problems getting UI elements to activate/deactivate on mouse over? 1 Answer
How do I get the width and height of text then apply it to a UI panel? 0 Answers
How can we access panel' s children for take Tags ? 1 Answer
Translate a game object on horizontal and vertical axis? 3 Answers
Problems with horizontal input. 0 and -1 both= false. 1 Answer