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.
 
 
 
Nydaliv/Assets/Scripts/UI/SplitSectionInHalf.cs

29 lines
814 B

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class SplitSectionInHalf : MonoBehaviour
{
[Tooltip("X=Left Y=Right")]
public Vector2 Padding;
public TextMeshProUGUI left;
public TextMeshProUGUI right;
IEnumerator SetWidth()
{
yield return new WaitForFixedUpdate();
float hori = GetComponent<RectTransform>().rect.width;
left.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, hori / 2);
right.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, hori / 2);
left.rectTransform.SetRight(-(hori / 2) + Padding.x);
right.rectTransform.SetLeft(-(hori / 2) + Padding.y);
}
void FixedUpdate()
{
StartCoroutine(SetWidth());
}
}