summaryrefslogtreecommitdiff
path: root/GameCode/SetWidthToTarget.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-11-02 11:51:31 +0800
committerchai <215380520@qq.com>2023-11-02 11:51:31 +0800
commit7f493f682503f5186308de7b8f74b5b49233cfe4 (patch)
tree8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/SetWidthToTarget.cs
+init
Diffstat (limited to 'GameCode/SetWidthToTarget.cs')
-rw-r--r--GameCode/SetWidthToTarget.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/GameCode/SetWidthToTarget.cs b/GameCode/SetWidthToTarget.cs
new file mode 100644
index 0000000..fa5c6b6
--- /dev/null
+++ b/GameCode/SetWidthToTarget.cs
@@ -0,0 +1,29 @@
+using UnityEngine;
+
+public class SetWidthToTarget : MonoBehaviour
+{
+ public RectTransform target;
+
+ public float padding;
+
+ public float minWidth = 800f;
+
+ private RectTransform rt;
+
+ private void Awake()
+ {
+ rt = GetComponent<RectTransform>();
+ if (rt.sizeDelta.x < minWidth)
+ {
+ rt.sizeDelta = new Vector2(minWidth, rt.sizeDelta.y);
+ }
+ }
+
+ private void Update()
+ {
+ if (target.sizeDelta.x + padding * 2f > minWidth && !Mathf.Approximately(rt.sizeDelta.x - padding * 2f, target.sizeDelta.x))
+ {
+ rt.sizeDelta = new Vector2(target.sizeDelta.x + padding * 2f, rt.sizeDelta.y);
+ }
+ }
+}