본문 바로가기
개발💻/Unity

[Unity] 말풍선 UGUI

by Sports Entrepreneur 2022. 11. 7.

 

using UnityEngine;
using TMPro;

public class SpeechBubble : MonoBehaviour
{
    public TextMeshProUGUI Speechtext;    // 말풍선 텍스트 
    public RectTransform rectSpeechBubble;// 말풍선 위치
    public float paddingOffset = 100.0f;  // 패딩의 offset

    void Update()
    {
        // 말풍선 y축 패딩값을 적용후 사이즈 변경
        rectSpeechBubble.SetSizeWithCurrentAnchors
            (RectTransform.Axis.Vertical, Speechtext.textBounds.size.y + paddingOffset);
        // 말풍선 x축 패딩값을 적용후 사이즈 변경
        rectSpeechBubble.SetSizeWithCurrentAnchors
            (RectTransform.Axis.Horizontal, Speechtext.textBounds.size.x + paddingOffset);
    }
}