using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlendShapesController : MonoBehaviour
{
private SkinnedMeshRenderer bodySkinnedMeshRenderer;
private bool randomizeNumbers = true;
// Start is called before the first frame update
void Start()
{
bodySkinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
StartCoroutine(RandomNumbers());
}
// Update is called once per frame
void Update()
{
if(randomizeNumbers == true)
{
StartCoroutine(RandomNumbers());
randomizeNumbers = false;
}
}
IEnumerator RandomNumbers()
{
int rand = Random.Range(0, 23);
bodySkinnedMeshRenderer.SetBlendShapeWeight(0, rand);
yield return new WaitForSeconds(0.3f);
randomizeNumbers = true;
}
}
Now I'm using a random number betwen 0 and 23 every 0.3f seconds. I want to change it so it will lerp in the SetBlendShapeWeight at index 0 but instead rand it will lerp from 0 to 23 then from 23 to 0 when done stop waiting seconds.
So the time or speed should be set for the lerp and according to that how much time to wait. For example if the lerp will take 5 seconds from 0 to 23 and then back from 23 to 0 then after 5 seconds start the Coroutine again.
The idea is to make some kind of mouth talk fake/cheat. So I want to mouth to be open/close smooth between 0 and 23 and then 23 to 0 before starting the new Coroutine and to be able to decide how much time it will take to make the lerp from 0 to 23 and 23 to 0.
In the screenshot when the blendshape of the mouth is set to 0 the mouth is open at 23 or 27 the mouth is closed. So I want to simulate mouth talking between this range of numbers for example each 0.3f make the mouth close/open then after 0.3f again mouth close/open and so on.