Skip to content

Instantly share code, notes, and snippets.

@edwardrowe
Created September 9, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardrowe/aa5fa3150d5d8c060eabf19f276746eb to your computer and use it in GitHub Desktop.
Save edwardrowe/aa5fa3150d5d8c060eabf19f276746eb to your computer and use it in GitHub Desktop.
Code used in reference to a comment on TextTyper blog. https://medium.com/@111896christopher/hey-edward-rowe-d7c78d08a124
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using RedBlueGames.Tools.TextTyper;
public class CVExample : MonoBehaviour
{
[SerializeField]
private InputField textInputField;
[SerializeField]
private Button submitInput;
[SerializeField]
private TextTyper typer;
private Dictionary<string, string> responses;
private void Awake()
{
this.typer.PrintCompleted.AddListener(this.HandlePrintCompleted);
this.submitInput.onClick.AddListener(this.HandleSubmit);
}
private void HandleSubmit()
{
var input = this.textInputField.text;
if (this.responses.ContainsKey(input))
{
var response = this.responses[input];
this.BeginPrintingText(response);
}
}
private void BeginPrintingText(string text)
{
this.typer.TypeText(text);
// Deactivate the buttons
}
private void HandlePrintCompleted()
{
// Activate the buttons here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment