using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BlendShapesController : MonoBehaviour
{
public Text[] texts;
public bool startTalking = false;
public float talkTime;
public float duration;
[Range(0, 100)]
public float valueRange;
private SkinnedMeshRenderer bodySkinnedMeshRenderer;
private bool isTalking = true;
// Start is called before the first frame update
void Start()
{
bodySkinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
}
// Update is called once per frame
void Update()
{
StartTalking();
if (startTalking && isTalking)
{
StartCoroutine(AnimateMouth());
StartCoroutine(TalkTime());
isTalking = false;
}
if (startTalking == false && isTalking == false)
{
isTalking = true;
}
}
//Lerp between startValue and endValue over 'duration' seconds
private IEnumerator LerpShape(float startValue, float endValue, float duration)
{
float elapsed = 0;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float value = Mathf.Lerp(startValue, endValue, elapsed / duration);
bodySkinnedMeshRenderer.SetBlendShapeWeight(0, value);
yield return null;
}
}
//animate open and closed, then repeat
public IEnumerator AnimateMouth()
{
while (startTalking == true)
{
yield return StartCoroutine(LerpShape(0, valueRange, duration));
yield return StartCoroutine(LerpShape(valueRange, 0, duration));
}
}
public IEnumerator TalkTime()
{
yield return new WaitForSeconds(talkTime);
startTalking = false;
}
public void StartTalking()
{
for (int i = 0; i < texts.Length; i++)
{
if (texts[i].text != "")
{
startTalking = true;
}
}
}
}
I want that if one of the ui texts is not empty and not disabled to start talking by calling the StartTalking method. The game start when all the ui texts are disabled one of them is not empty but they are all disabled. And during the game they are turning disabled enabled in the game and get empty not empty. On the ui text is not empty.
The problem is in the Inspector I can't drag disabled ui texts to the array of the script.
All the ui texts are childs under their own parents that are childs of the prefab name Game UI Texts.
This are the ui texts in the screenshot that should be dragged to the sccript on the right in the Inspector :
Scene Text , Description Text , and Long Distance Description Text
The main goal is to use one script to control automatic the talking with the text in the game. When there is a text in the game on the screen StartTalking and stop talking when there is no text on the screen.