Skip to content
Snippets Groups Projects
Commit 399d0f56 authored by John Schihada's avatar John Schihada
Browse files

Fixed typing-bug of TaskCharakter

parent ae97405e
No related branches found
No related tags found
No related merge requests found
fileFormatVersion: 2
guid: eec83b50c1e0c604aa91430f72c8dbb0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -9,9 +9,12 @@ public class CharacterDialog : MonoBehaviour ...@@ -9,9 +9,12 @@ public class CharacterDialog : MonoBehaviour
public TextMeshPro textDisplay; public TextMeshPro textDisplay;
public TextMeshPro textHint; public TextMeshPro textHint;
public string[] sentences; public string[] sentences;
private int index; private int sentenceIndex;
private int letterIndex = 0;
private bool typingActive = false;
//speed for typing the Text //speed for typing the Text
public float typingSpeed; public float typingSpeed;
private float timer = 0;
//Only reset once after Player is out of range of the TaskCharacter //Only reset once after Player is out of range of the TaskCharacter
private bool textReseted = true; private bool textReseted = true;
...@@ -23,12 +26,15 @@ void Start() ...@@ -23,12 +26,15 @@ void Start()
{ {
CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence); CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence);
//Type first sentence //Type first sentence
StartCoroutine(Type()); typingActive = true;
TypeFkt();
} }
private void Update() private void Update()
{ {
TypeFkt();
if(!pushoutSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone()) 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 //Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key
...@@ -43,20 +49,48 @@ private void Update() ...@@ -43,20 +49,48 @@ private void Update()
//Type a sentence slowly //Type a sentence slowly
IEnumerator Type() { IEnumerator Type() {
foreach (char letter in sentences[index].ToCharArray()) { foreach (char letter in sentences[sentenceIndex].ToCharArray()) {
textDisplay.text += letter; textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed); yield return new WaitForSeconds(typingSpeed);
} }
} }
public void TypeFkt() {
if (typingActive)
{
if (this.timer >= this.typingSpeed)
{
if (letterIndex < sentences[sentenceIndex].Length)
{
textDisplay.text += sentences[sentenceIndex].ToCharArray()[letterIndex];
letterIndex++;
}
else
{
this.typingActive = false;
letterIndex = 0;
}
this.timer = 0;
}
else
{
this.timer += Time.deltaTime;
}
}
}
public void NextSentence() { public void NextSentence() {
//-2 because the last sentence is only for SucceededPushout-Purposes //-2 because the last sentence is only for SucceededPushout-Purposes
if (index < sentences.Length - 2) if (sentenceIndex < sentences.Length - 2)
{ {
index++; sentenceIndex++;
letterIndex = 0;
typingActive = true;
timer = 0;
textDisplay.text = ""; textDisplay.text = "";
StartCoroutine(Type()); TypeFkt();
textReseted = false; textReseted = false;
} }
else { else {
...@@ -65,21 +99,27 @@ public void NextSentence() { ...@@ -65,21 +99,27 @@ public void NextSentence() {
} }
public void ResetSentence() { public void ResetSentence() {
index = 0; sentenceIndex = 0;
letterIndex = 0;
typingActive = true;
timer = 0;
textDisplay.text = ""; textDisplay.text = "";
//Type first sentence again //Type first sentence again
StartCoroutine(Type()); TypeFkt();
textReseted = true; textReseted = true;
} }
public void PushoutSucceededSentence(Fact startFact) { public void PushoutSucceededSentence(Fact startFact) {
textDisplay.text = ""; textDisplay.text = "";
//Last Sentence is the Pushout-Sentence //Last Sentence is the Pushout-Sentence
index = sentences.Length - 1; sentenceIndex = sentences.Length - 1;
letterIndex = 0;
typingActive = true;
timer = 0;
pushoutSucceeded = true; pushoutSucceeded = true;
//Disable Hint With Enter-Key for Talking //Disable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = false; textHint.GetComponent<MeshRenderer>().enabled = false;
//Type final message //Type final message
StartCoroutine(Type()); TypeFkt();
} }
} }
...@@ -64,6 +64,11 @@ void Update() ...@@ -64,6 +64,11 @@ void Update()
else { else {
//disable enter-key for talking //disable enter-key for talking
setPlayerInTalkingZone(false); setPlayerInTalkingZone(false);
//Change to walking State after Talking Zone so that player can stay inside the radiusAroundObject
rotate = false;
this.timer = 0;
//Change boolean for switching to Walking-State in AnimationController
anim.SetBool("standing", false);
} }
//Calculate distance from tree, so that the TaskCharacter only walks in a specific radius around the tree //Calculate distance from tree, so that the TaskCharacter only walks in a specific radius around the tree
...@@ -142,6 +147,18 @@ public void stopHappy(Fact startFact) { ...@@ -142,6 +147,18 @@ public void stopHappy(Fact startFact) {
//Set Variable in animationController to change the state //Set Variable in animationController to change the state
anim.SetBool("solved", false); anim.SetBool("solved", false);
happy = false; happy = false;
resetToStart();
}
public void resetToStart() {
//On Reset: Player must go into walking state, because it could be that after the happy/running-animation the player is
//out of radius and rotates -> AnimationController StateMachine always changes into walking-state after hyppAnimation
walking = true;
standing = false;
rotate = true;
nextRotation = 0;
rotationUnits = 0;
playerInTalkingZone = false;
} }
//Static Method for CharacterDialog //Static Method for CharacterDialog
......
fileFormatVersion: 2
guid: b543d9677cbde534ab69c0a229bfdb06
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -14,13 +14,13 @@ AnimatorController: ...@@ -14,13 +14,13 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: solved - m_Name: solved
m_Type: 4 m_Type: 4
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
...@@ -55,9 +55,6 @@ AnimatorStateTransition: ...@@ -55,9 +55,6 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: m_Name:
m_Conditions: m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: standing
m_EventTreshold: 0
- m_ConditionMode: 2 - m_ConditionMode: 2
m_ConditionEvent: solved m_ConditionEvent: solved
m_EventTreshold: 0 m_EventTreshold: 0
...@@ -100,34 +97,6 @@ AnimatorStateTransition: ...@@ -100,34 +97,6 @@ AnimatorStateTransition:
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1
--- !u!1101 &1101526424927387364
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: standing
m_EventTreshold: 0
- m_ConditionMode: 2
m_ConditionEvent: solved
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102119675311824806}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 3
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101676305976220748 --- !u!1101 &1101676305976220748
AnimatorStateTransition: AnimatorStateTransition:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
...@@ -271,7 +240,6 @@ AnimatorState: ...@@ -271,7 +240,6 @@ AnimatorState:
m_CycleOffset: 0 m_CycleOffset: 0
m_Transitions: m_Transitions:
- {fileID: 1101065367606003302} - {fileID: 1101065367606003302}
- {fileID: 1101526424927387364}
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0} m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0 m_IKOnFeet: 0
......
fileFormatVersion: 2
guid: ac72be71662640f4ab0aaf102090fb95
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment