From 7ba5981a03edd680f3275efe79561ef5cb3c5427 Mon Sep 17 00:00:00 2001 From: Rizvee Date: Mon, 21 Feb 2022 15:05:53 -0600 Subject: [PATCH] Finished basics of textbox --- Assets/Scene 1 Assets/Dialogue.cs | 25 ++++++++++++++++++++++--- Assets/Scene 1 Assets/Textbox.prefab | 2 ++ Assets/Scenes/Scene1.unity | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Assets/Scene 1 Assets/Dialogue.cs b/Assets/Scene 1 Assets/Dialogue.cs index 51ddd91..ab5a315 100644 --- a/Assets/Scene 1 Assets/Dialogue.cs +++ b/Assets/Scene 1 Assets/Dialogue.cs @@ -6,6 +6,7 @@ using TMPro; public class Dialogue : MonoBehaviour { public TMP_Text textbox; + public TMP_Text arrow; public List pages = new List(); int curPage = 0; public bool isOpen = true; @@ -15,7 +16,8 @@ public class Dialogue : MonoBehaviour //used to print the first x letters of the text int cCount = 0; //changes the pace at which chars appear - float pace = 10.0f; + //in seconds + float pace = 0.05f; float elapsed = 0f; // Start is called before the first frame update void Start() @@ -23,6 +25,7 @@ public class Dialogue : MonoBehaviour if(pages.Count > 0) { textbox.text = pages[0]; + arrow.text = ""; } } @@ -42,6 +45,15 @@ public class Dialogue : MonoBehaviour //checks if all of the characters are on the page if(cCount >= pages[curPage].Length) { + //prints the "next" arrow when at end of page except last page + if(curPage < pages.Count - 1) + { + arrow.text = ">"; + } + else + { + arrow.text = "x"; + } elapsed = 0; if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) @@ -49,12 +61,15 @@ public class Dialogue : MonoBehaviour //scroll through textbox using any movement key if(curPage >= pages.Count - 1) { + //exits the textbox isOpen = false; Movement.pause = false; textTest.SetActive(false); } else { + //resets pace of chars + arrow.text = ""; ++curPage; cCount = 0; } @@ -62,11 +77,15 @@ public class Dialogue : MonoBehaviour } else { + //writes chars at specified pace elapsed += Time.deltaTime; - if(elapsed % pace == 0) + if(elapsed > pace) { - textbox.text = pages[curPage].Substring(0, ++cCount); + ++cCount; + textbox.text = pages[curPage].Substring(0, cCount); + elapsed = 0; } + //skip ahead if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) { diff --git a/Assets/Scene 1 Assets/Textbox.prefab b/Assets/Scene 1 Assets/Textbox.prefab index 5c093ae..a042329 100644 --- a/Assets/Scene 1 Assets/Textbox.prefab +++ b/Assets/Scene 1 Assets/Textbox.prefab @@ -495,6 +495,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: textbox: {fileID: 7059772333148747626} + arrow: {fileID: 7395190149993767727} + pages: [] isOpen: 0 textTest: {fileID: 7059772332581294260} --- !u!1 &7059772333148747624 diff --git a/Assets/Scenes/Scene1.unity b/Assets/Scenes/Scene1.unity index 4f49d94..479f0dc 100644 --- a/Assets/Scenes/Scene1.unity +++ b/Assets/Scenes/Scene1.unity @@ -811,7 +811,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3758862681294202868, guid: 6ea336e93a8128346aad568255a7e6af, type: 3} propertyPath: pages.Array.data[0] - value: '"this is a test"' + value: '"this is a testsadfasdfsadfsadfasdfasdfasdfasdf"' objectReference: {fileID: 0} - target: {fileID: 3758862681294202868, guid: 6ea336e93a8128346aad568255a7e6af, type: 3} propertyPath: pages.Array.data[1]