using System.Collections; using System.Collections.Generic; using UnityEngine; public class ModifyBlendShape : MonoBehaviour { private SkinnedMeshRenderer m_SkinnedMeshRenderer; private void Awake(){ m_SkinnedMeshRenderer = this.GetComponent(); StartCoroutine(BlendShapeRoutineEyes()); //StartCoroutine(BlendShapeRoutineMouth()); } private IEnumerator BlendShapeRoutineEyes(){ yield return new WaitForSecondsRealtime(Random.Range(5f, 10f)); // Blink! m_SkinnedMeshRenderer.SetBlendShapeWeight(0, Mathf.SmoothStep(0, 100, 1)); m_SkinnedMeshRenderer.SetBlendShapeWeight(1, Mathf.SmoothStep(0, 100, 1)); yield return new WaitForSecondsRealtime(Random.Range(0.25f, 0.75f)); m_SkinnedMeshRenderer.SetBlendShapeWeight(0, Mathf.SmoothStep(0, 100, 0)); m_SkinnedMeshRenderer.SetBlendShapeWeight(1, Mathf.SmoothStep(0, 100, 0)); StartCoroutine(BlendShapeRoutineEyes()); } private void Update(){ BlendNoise(); } private void BlendNoise(){ float noise = Mathf.PerlinNoise(Time.time * 0.1f, Time.time * 0.1f); // m_SkinnedMeshRenderer.SetBlendShapeWeight(0, Mathf.SmoothStep(0, 100, noise)); // m_SkinnedMeshRenderer.SetBlendShapeWeight(1, Mathf.SmoothStep(0, 100, noise)); m_SkinnedMeshRenderer.SetBlendShapeWeight(2, Mathf.SmoothStep(0, 75, noise)); m_SkinnedMeshRenderer.SetBlendShapeWeight(3, Mathf.SmoothStep(0, 75, noise)); } private IEnumerator BlendShapeRoutineMouth(){ yield return new WaitForSeconds(1); } }