IEnumerator WaitForFinished() { yield return(new WaitForSeconds(1)); while (chatProcesser.enabled) { yield return(new WaitForSeconds(0.1f)); } GameObject.Destroy(chatBubble.gameObject); chatBubble = null; chatProcesser = null; isSpeaking = false; }
public void Speak(string message) { // do not speak if already speaking if (Canvas && ChatAnchor && ChatOutputProfile && ChatBubblePrefab && chatBubble == null) { isSpeaking = true; chatBubble = GameObject.Instantiate(ChatBubblePrefab, new Vector3(-100000, -10000, 0), Quaternion.identity, Canvas.transform); ChatAnchor.BindAttachedBubble(chatBubble); chatBubble.BindNameValue(ChatName); chatProcesser = chatBubble.gameObject.AddComponent <ChatOutputProcesser>(); chatProcesser.enabled = false; chatProcesser.Profile = ChatOutputProfile; chatProcesser.Value = message; chatProcesser.AudioSource = AudioSource; chatProcesser.enabled = true; chatBubble.gameObject.SetActive(true); StartCoroutine(WaitForFinished()); } }