public void displayText(string text) { StopAllCoroutines(); shownString = ""; fullString = capitaliseFirstLetter(text); state = conversationState.npcSpeaking; StartCoroutine(RevealString()); }
void Update() { if (Input.GetKeyDown(KeyCode.LeftControl)) { setStateNone(); } if (state == conversationState.npcSpeaking && dialogType != dialog.greeting) { if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) { skipText(); } } else //More text is set when the current line is finished printing, but there is more dialogue from the NPC waiting to be displayed upon pressing shift if (state == conversationState.moreText) { //Alibi and events witnessed go to more text after each time the NPC speaks, and wait for either continue or accuse if (dialogType == dialog.alibi || dialogType == dialog.eventsWitnessed) { if (Input.GetKeyDown(KeyCode.F)) { AccuseOfLying(); } if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { if (dialogueQueue.Count > 0) { displayText(dialogueQueue.Dequeue()); testimonyQueue.Dequeue(); Testimony testimony = testimonyQueue.Peek(); if (!testimony.truth && testimony.firstTimeTold) speakingNPC.stress += speakingNPC.stressIncrements; } else { dialogType = dialog.greeting; displayText("Can I help you with anything else?"); testimonyQueue.Clear(); state = conversationState.playerInput; } } } else if (dialogType == dialog.suspect || dialogType == dialog.accusation || dialogType == dialog.introduction) { if (dialogueQueue.Count > 0) { if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ) { displayText(dialogueQueue.Dequeue()); } } else { if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ) { dialogType = dialog.greeting; displayText("Can I help you with anything else?"); testimonyQueue.Clear(); state = conversationState.playerInput; } /* else if (Input.GetKeyDown(KeyCode.F)) { AccuseOfLying(); } */ } } else if (dialogType == dialog.lockedOut) { if (dialogueQueue.Count > 0) { if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { displayText(dialogueQueue.Dequeue()); } } else { if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { setStateNone(); } } } } //Player input is when the NPC has finished talking and the player uses the menu to respond to them else if (state == conversationState.playerInput) { if (Input.GetKeyDown("w") || Input.GetKey(KeyCode.UpArrow)) { selected = Math.Max(0, selected - 1); } else if (Input.GetKeyDown("s") || Input.GetKey(KeyCode.DownArrow)) { selected = Math.Min(responses.Count - 1, selected + 1); } if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { selectResponse(selected); } } }
void Start() { pg = gameObject.GetComponent<PlotGenerator>(); uiManager = gameObject.GetComponent<UIManager>(); audioSource = gameObject.GetComponent<AudioSource>(); letterSound = Resources.Load<AudioClip>("Audio/text-letter"); //Load gameobjects textPanel = GameObject.Find("Text Panel"); TextArea = GameObject.Find("Text Area").GetComponent<Text>(); responseArea = GameObject.Find("Response Area").GetComponent<Text>(); nameText = GameObject.Find("Name Text").GetComponent<Text>(); state = conversationState.none; responses = new List<string>(); dialogueQueue = new Queue<string>(); testimonyQueue = new Queue<Testimony>(); }
void skipText() { StopAllCoroutines(); shownString = fullString; TextArea.text = shownString; if (dialogType == dialog.alibi || dialogType == dialog.eventsWitnessed || dialogType == dialog.suspect || dialogueQueue.Count > 0) { state = conversationState.moreText; } else { setUpDialogOptions(); if (speakingNPC.isAlive) dialogType = dialog.greeting; else dialogType = dialog.corpse; state = conversationState.playerInput; } }
void setStateNone() { state = conversationState.none; dialogType = dialog.none; testimonyQueue.Clear(); dialogueQueue.Clear(); selected = 0; shownString = ""; fullString = ""; }
IEnumerator RevealString() { foreach (char letter in fullString.ToCharArray()) { shownString += letter; if (state == conversationState.npcSpeaking || state == conversationState.playerInput)audioSource.PlayOneShot(letterSound); if(dialogType != dialog.corpse && dialogType != dialog.murderAccusation) { float combinedLetterDelay = letterDelay; if (letter == ',') combinedLetterDelay += 0.09f; //add a pause to commas else if (letter == '.') combinedLetterDelay += 0.12f; //slightly longer pause to full stops //chance to stammer between each word to indicate stress else if (letter == ' ') { float chanceToStutter = UnityEngine.Random.Range(0.1f, 1.0f); if (chanceToStutter < speakingNPC.stress) { combinedLetterDelay += UnityEngine.Random.Range(0.09f, 0.2f); } } yield return new WaitForSeconds(combinedLetterDelay); } else yield return new WaitForSeconds(letterDelay); } if (shownString == fullString) { if (dialogType == dialog.alibi || dialogType == dialog.eventsWitnessed || dialogType == dialog.suspect || dialogueQueue.Count > 0) { state = conversationState.moreText; } else { setUpDialogOptions(); if (speakingNPC.isAlive) dialogType = dialog.greeting; else dialogType = dialog.corpse; state = conversationState.playerInput; } StopAllCoroutines(); } }