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.

33 lines
970 B

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;
private void OnEnable() {
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, 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);
}
}