- Home /
How to change the Width and Height in the script C#? (New Gui Unity 4.6 beta)
Hello, how to change the Width and Height in new gui:
I tried:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class RectTest : MonoBehaviour {
public Button MyButton;
void Start () {
MyButton.height = 700; //not working
MyButton.transform.height = 700; //not working
MyButton.transform.position.height = 700; //not working
MyButton.gameObject.transform.position.height = 700; //not working
}
}
Thanks!
width_height.jpg
(15.0 kB)
Comment
Answer by Marc Zaku · Jan 23, 2015 at 09:33 AM
RectTransform t = transform as RectTransform;
Vector2 dimension = t.sizeDelta;
dimension.x = preferredWidth;
dimension.y = preferredHeight;
t.sizeDelta = dimension;