- Home /
RectTransform.rect.Set doesn't work!
I tried to set the position of the buttons automatically at startup. In the documentation, as well as on the Internet, I was prompted to use something like this:
 public float MaxButtonWidth = 200.0f;
 public float MaxButtonHeight = 32.0f;
 public float PanelButtonsYPosition = -4.0f;
 public Button[] ButtonsArray;
 void Start()
 {
     int index;
     for(index = 0; index<ButtonsArray.Length; index++)
     {
         ButtonsArray[index] = ButtonsArray[index].GetComponent<Button>();
         RectTransform MyRectTransform = ButtonsArray[index].GetComponent<RectTransform>();
         MyRectTransform.rect.Set(
             index*MaxButtonWidth+4.0f, PanelButtonsYPosition,
             MaxButtonWidth, MaxButtonHeight
             );
         MyRectTransform.pivot.Set(0, 0);
     }
 }
(i also tried set the pivot position too)
But it doesn't work. I even tried to use this code:
         MyRectTransform.rect = Rect(
             index*MaxButtonWidth+4.0f, PanelButtonsYPosition,
             MaxButtonWidth, MaxButtonHeight
             );
But this does not work either. What did I do wrong?
               Comment
              
 
               
              Answer by Pavel_D · Oct 19, 2016 at 01:34 PM
Thats post completely answered your question, also my fast answer its Rect only for calculation, RectTransform.sizeDelta for applying weight or height http://answers.unity3d.com/questions/973572/recttransform-wont-resize.html
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                