Guest User

RectTransormWidthLock

a guest
Sep 6th, 2016
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. // Locks width, but not height.
  4. [ExecuteInEditMode, RequireComponent(typeof(RectTransform))]
  5. public class RectTransormWidthLock : MonoBehaviour
  6. {
  7.     private new RectTransform transform;
  8.  
  9.     [SerializeField] private float width = 1f;
  10.  
  11.     void Start()
  12.     {
  13.         this.transform = this.GetComponent<RectTransform>();
  14.     }
  15.  
  16.     void Update()
  17.     {
  18.         this.transform.sizeDelta = new Vector2(width, this.transform.sizeDelta.y);
  19.     }
  20. }
RAW Paste Data