You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.0 KiB

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;
public Vector2 Size => new(x2 - x1, y2 - y1);
private void OnEnable() {
Singleton = this;
top = transform.Find("Top").GetComponent<EdgeCollider2D>();
bottom = transform.Find("Bottom").GetComponent<EdgeCollider2D>();
left = transform.Find("Left").GetComponent<EdgeCollider2D>();
right = transform.Find("Right").GetComponent<EdgeCollider2D>();
}
private void Update() {
Vector2 v1 = new Vector2(x1, y2);
Vector2 v2 = new Vector2(x2, y2);
Vector2 v3 = new Vector2(x1, y1);
Vector2 v4 = new Vector2(x2, y1);
top.points = new[] {v1, v2};
bottom.points = new[] {v3, v4};
left.points = new[] {v1, v3};
right.points = new[] {v2, v4};
playGround.localPosition = new Vector3((x1 + x2) / 2, (y1 + y2) / 2, 0);
playGround.localScale = Size;
}
}