Code Examples

v4.0

Creating a Speak() method

While there are many ways to play audio, using the PlayClip method on the Voice.cs script is an easy way to get audio to play. You can create a very simple Speak() method to use as well:

public void Speak(string line, emotion = "", index = -1) 
    => voice.PlayClip(audioSource, line, emotion, index);

If this is attached to your Player() class, you can then easily get your players to speak with something like:

// Play a random clip form "Level Up", ignoring emotions
player.Speak("LevelUp");

// Play a random clip from "Let's Get Out of Here" with the "Scared" emotion
player.Speak("LetsGetOutOfHere", "Scared");

// Play a specific clip from "Great Loot", ignoring emotions
player.Spkea("GreatLoot", "", 2);

Last updated