Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Assets/Graphics/Thumbs.db
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Scenes/GenerationTestScene.unity
Binary file not shown.
Binary file modified Assets/Scenes/TestScene.unity
Binary file not shown.
93 changes: 93 additions & 0 deletions Assets/Scripts/TextBoxManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TextBoxManager : MonoBehaviour
{
/**
For a text box to simulate a conversation between two characters.

Things that need to be specified:
- names of the first and second speaker.
- file that contains the dialogue.

In the text file, format should look something like:
Zimri: Hello.
NPC: I must go.
Good bye!
Zimri: Have a nice day.
If a speaker has more than one line, you can include the speaker's name in each
line after the first, but it is not necessary.
See sampledialogue.txt for an example.
**/

public GameObject textBox;

public Text thedialogue;

public TextAsset dialogue;
public string[] dialoguelines;

int currentLine = 0;
int endAtLine;
public string firstCharacter;
public string secondCharacter;
bool firstSpeaker = true;

// Use this for initialization
void Start()
{
//Each line in the text file stored into dialogueLines.
if (dialogue != null)
{
dialoguelines = (dialogue.text.Split('\n'));
}

if (endAtLine == 0)
{
endAtLine = dialoguelines.Length - 1;
}
}

// Update is called once per frame
void Update()
{
//Detects a change in speaker.
if (dialoguelines[currentLine].Contains(firstCharacter))
{
firstSpeaker = true;
}

if (dialoguelines[currentLine].Contains(secondCharacter))
{
firstSpeaker = false;
}

//Text color changes depending on speaker.
if (firstSpeaker == true)
{
thedialogue.color = Color.red;
}
else
{
thedialogue.color = Color.blue;
}

//Display line.
thedialogue.text = dialoguelines[currentLine];

//Press U for next line.
if (Input.GetKeyDown(KeyCode.U))
{
currentLine += 1;
}

//Text box disappears after all lines have been spoken.
if (currentLine > endAtLine)
{
textBox.SetActive(false);
}


}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/TextBoxManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/Text/sampleDialogue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Zimri: Hello.
NPC: Good morning.
Zimri: Good bye.
NPC: Wish you well.
Have a nice day!
8 changes: 8 additions & 0 deletions Assets/Text/sampleDialogue.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 5.3.2p1
m_EditorVersion: 5.3.2f1
m_StandardAssetsVersion: 0
Binary file modified ProjectSettings/QualitySettings.asset
Binary file not shown.