본문 바로가기
개발/C#

유니티 C# 스킨드 메쉬 랜더러 Blend Shape 설정 간단 사용법

by SPNK 2022. 7. 5.
반응형
  • Blend Shape이란?

스킨드 매쉬 랜더러 애니메이션을 적용하고 싶을때 사용

 

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

public class Example : MonoBehaviour
{
    SkinnedMeshRenderer skinnedMeshRenderer;


    private void Awake()
    {
        skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
    }

    private void OnEnable()
    {
        StartCoroutine(SetBlendShapeCoroution(skinnedMeshRenderer));
    }

    private void OnDisable()
    {
        StopAllCoroutines();
    }


    IEnumerator SetBlendShapeCoroution(SkinnedMeshRenderer mesh)
    {
        float blend = 0;

        while (blend < 100)
        {
            blend += 1f;
            mesh.SetBlendShapeWeight(0, blend);

            yield return new WaitForSeconds(0.01f);
        }

        mesh.SetBlendShapeWeight(0, 100);
    }
}
반응형

댓글