Adventure Creator Wikia
Advertisement

The [expression:Name] token can be used in a character's speech text to change their expression midway through. However, this only affects the expression of the character who is speaking.

The script below allows you to change the Player's expression while any character is speaking, by using the [PlayerExpression:Name] token instead. To use it, paste its contents into a script named CustomPlayerExpressions.cs, and attach to your scene.

CustomPlayerExpressions.cs:

	using UnityEngine;
	using AC;

	public class CustomPlayerExpressions : MonoBehaviour
	{

		private const string tokenName = "PlayerExpression";

		private void OnEnable ()
		{
			KickStarter.dialog.SpeechEventTokenKeys = new string[1] { tokenName };
			EventManager.OnSpeechToken += OnSpeechToken;
		}

		private void OnDisable () { EventManager.OnSpeechToken -= OnSpeechToken; }

		private void OnSpeechToken (AC.Char speakingCharacter, int lineID, string tokenKey, string tokenValue)
		{
			if (tokenKey == tokenName)
			{
				int expressionID = KickStarter.player.GetExpressionID (tokenValue);
				KickStarter.player.SetExpression (expressionID);
			}
		}

	}
Advertisement