using System; using JetBrains.Annotations; using UnityEngine; [ExecuteInEditMode] public class BorderSize : MonoBehaviour { public float x1, x2, y1, y2; private EdgeCollider2D top, bottom, left, right; public Transform playGround; public static BorderSize Singleton; private void OnEnable() { Singleton = this; top = transform.Find("Top").GetComponent(); bottom = transform.Find("Bottom").GetComponent(); left = transform.Find("Left").GetComponent(); right = transform.Find("Right").GetComponent(); } private void Update() { Vector2 v1 = new Vector2(x1, y1); Vector2 v2 = new Vector2(x2, y1); Vector2 v3 = new Vector2(x1, y2); Vector2 v4 = new Vector2(x2, y2); top.points = new[] {v1, v2}; bottom.points = new[] {v3, v4}; left.points = new[] {v1, v3}; right.points = new[] {v2, v4}; playGround.localPosition = new Vector3((x2 + x1) / 2, (y2 + y1) / 2, 0); playGround.localScale = new Vector3(x2 - x1, y2 - y1, 1); } }