Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SelectionBoxTest : MonoBehaviour
- {
- public Transform startTransform;
- public Transform endTransform;
- public RectTransform selectionBox;
- // Update is called once per frame
- void Update()
- {
- Vector3 startPos = Camera.main.WorldToScreenPoint(startTransform.position);
- Vector3 curPos = Camera.main.WorldToScreenPoint(endTransform.position);
- float width = curPos.x - startPos.x;
- float height = curPos.y - startPos.y;
- Vector3 minScreenPos = new Vector3(Mathf.Min(curPos.x, startPos.x), Mathf.Min(curPos.y, startPos.y));
- Vector3 maxScreenPos = new Vector3(Mathf.Max(curPos.x, startPos.x), Mathf.Max(curPos.y, startPos.y));
- selectionBox.pivot = Vector2.zero;
- selectionBox.anchoredPosition = minScreenPos;
- selectionBox.sizeDelta = new Vector2(Mathf.Abs(width), Mathf.Abs(height));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement