Adventure Creator Wikia
Advertisement

The Variable: Check random number can be used before dialogue to run different speech lines based on a random value, but this script allows you to play random dialogue from within a single Dialogue: Play speech Action.  Note, however, that this is not possible when lipsyncing or speech audio is involved.

To use it:

  1. Create a new C# script named RandomDialogue and attach it to a GameObject in the scene
  2. Separate random dialogue lines with "||" in your speech text. For example, Hi||Hello.

RandomDialogue.cs:

using System;
using UnityEngine;
using AC;

public class RandomDialogue : MonoBehaviour
{

	private void OnEnable () { EventManager.OnStartSpeech_Alt += StartSpeech; }
	private void OnDisable () { EventManager.OnStartSpeech_Alt -= StartSpeech; }

	private void StartSpeech (Speech speech)
	{
		if (speech.OriginalText.Contains ("||"))
		{
			string[] possibleValues = speech.OriginalText.Split (new string[] { "||" }, StringSplitOptions.None);
			int randomIndex = UnityEngine.Random.Range (0, possibleValues.Length);
			string randomValue = possibleValues[randomIndex];
			speech.ReplaceDisplayText (randomValue);
		}
	}

}
Advertisement