Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using static TaskCharakterAnimation;
public class CharacterDialog : MonoBehaviour
{
public TextMeshPro textDisplay;
public TextMeshPro textHint;
public string[] sentences;
private int index;
//speed for typing the Text
public float typingSpeed;
//Only reset once after Player is out of range of the TaskCharacter
private bool textReseted = true;
//If pushoutSucceeded -> Disable Talking with TaskCharacter
private bool pushoutSucceeded = false;
// Start is called before the first frame update
void Start()
{
CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence);
//Type first sentence
StartCoroutine(Type());
}
private void Update()
{
if(!pushoutSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone())
{
//Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key
NextSentence();
}
else if (!pushoutSucceeded && !TaskCharakterAnimation.getPlayerInTalkingZone() && !textReseted)
{
//Reset Sentence if Player is out of range of the TaskCharacter and it's not already reseted
ResetSentence();
}
}
//Type a sentence slowly
IEnumerator Type() {
foreach (char letter in sentences[index].ToCharArray()) {
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence() {
//-2 because the last sentence is only for SucceededPushout-Purposes
if (index < sentences.Length - 2)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
textReseted = false;
}
else {
textDisplay.text = "";
}
}
public void ResetSentence() {
index = 0;
textDisplay.text = "";
//Type first sentence again
StartCoroutine(Type());
textReseted = true;
}
public void PushoutSucceededSentence(Fact startFact) {
textDisplay.text = "";
//Last Sentence is the Pushout-Sentence
index = sentences.Length - 1;
pushoutSucceeded = true;
//Disable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = false;
//Type final message
StartCoroutine(Type());
}
}