소소한 개발 공부

[Unity] TextMeshPro Dilate script로 제어하기 how to edit TextMeshPro Dilate 본문

개발/Unity

[Unity] TextMeshPro Dilate script로 제어하기 how to edit TextMeshPro Dilate

이내내 2022. 10. 5. 23:02

https://answers.unity.com/questions/1676414/how-to-edit-text-mesh-pro-face-dilate-through-scri.html

 

How to edit Text Mesh Pro face dilate through script - Unity Answers

 

answers.unity.com

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class testdilate : MonoBehaviour
{
    public TextMeshProUGUI bi;
    
    public void OnClick()
    {
        StartCoroutine(StartSFX());
    }
    IEnumerator StartSFX()
    {
        float value = 0.5f;
        float time = 0f;
        Color color = bi.color;
    
        while (value > -1f)
        {
            time += Time.deltaTime;
            value = Mathf.Lerp(0.5f, -1f, time);
            bi.fontMaterial.SetFloat(ShaderUtilities.ID_FaceDilate, value);

            color.a = Mathf.Lerp(1f, 0f, time);
            bi.color = color;
            yield return null;
        }
    }
}

TMP material 과 Script

천천히 사라지는 연출을 하고자 했다. TextMeshPro - Face Dilate 값을 에디터 상에서 조절하니 꽤나 그럴 듯해 보여서 스크립트로 활용했다.

예쁘다!