UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an image aligner"
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ImageAligner : MonoBehaviour { public RectTransform image; public float borderPercent; private RectTransform selfRectTransform; // Start is called before the first frame update void Start() { selfRectTransform = GetComponent<RectTransform>(); AlignObjects(); } // Update is called once per frame void Update() { AlignObjects(); } private void AlignObjects() { float offset = borderPercent * 2 * selfRectTransform.rect.width; image.sizeDelta = new Vector2(selfRectTransform.rect.width - offset, selfRectTransform.rect.height-offset); } }