Animation state machine: Imgur: The magic of the Internet
(Confession, animator made this, idk if it’s proper form at all)
Animation controller (ignore the non-animation stuff, I’ve got some other functionality tacked on here):
using System;
using System.Collections;
using UnityEngine;
namespace LangLand.Script
{
[RequireComponent(typeof(AudioSource))]
public class NPC : Character
{
private AudioSource audioSource;
private Animator animator;
private void Awake()
{
audioSource = GetComponent();
animator = GetComponentInChildren();
}
///
/// Has the NPC speak
///
/// Text displayed while NPC is speaking
/// Audio clean played while NPC is speaking
/// Method to be called when NPC finishes speaking
public override void Speak(string transcript, AudioClip audioClip, Action callback)
{
StartCoroutine(PerformSpeak(transcript, audioClip, callback));
}
public void Dance()
{
ResetAnimations();
animator.SetBool(“Dance”, true);
}
public void Run()
{
ResetAnimations();
animator.SetBool(“Run”, true);
}
public void Sit()
{
ResetAnimations();
animator.SetBool(“Sit”, true);
}
public void ResetAnimations()
{
animator.SetBool(“Run”, false);
animator.SetBool(“Sit”, false);
animator.SetBool(“Dance”, false);
}
///
/// Performs the actual speaking of the NPC
///
/// Text displayed while NPC is speaking
/// Audio clean played while NPC is speaking
/// Method to be called when NPC finishes speaking
/// Unity required IEnumerator
private IEnumerator PerformSpeak(string transcript, AudioClip audioClip, Action callback)
{
yield return new WaitUntil(() => hackyHack);
speechBubble.gameObject.SetActive(true);
speechBackground.gameObject.SetActive(true);
hackyHack = true;
Debug.LogError(“Hackyachck”);
TextMesh Text = GetComponentInParent ();
//speechBubble.
Text = transcript;
audioSource.PlayOneShot(audioClip);
yield return new WaitForSeconds(audioClip.length);
StopSpeaking();
callback(false);
}
///
/// Has the character stop speaking
///
private void StopSpeaking()
{
speechBubble.text = string.Empty;
audioSource.Stop();
speechBubble.gameObject.SetActive(false);
speechBackground.gameObject.SetActive(false);
Animation.Play (false); //stop playing the talking animation
}
}
}
The timelines are currently empty, but I know how to make basic splines, etc. The characters themselvse aren’t really moving much, but I was thinking I’d use the timelines as a vehicle for holding animations over time, if that makes sense.