-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab433fe
commit 99942f4
Showing
3 changed files
with
56 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,73 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
using TMPro; | ||
|
||
public class Conversation : MonoBehaviour | ||
{ | ||
[Header("Conversation Configuration")] | ||
[SerializeField] private TMPro.TextMeshProUGUI textMeshPro; | ||
[SerializeField] private TextMeshProUGUI textMeshPro; | ||
[SerializeField] private float typingSpeed; | ||
[SerializeField] private string[] phrases = { "Hey, this is the shop!", "Please, choose your next weapon!", "Let the carnage begin!" }; | ||
[SerializeField] private float wordWait; | ||
[SerializeField] private string[] phrases; | ||
[SerializeField] private string[] phrasesBeforeBoss; | ||
private bool _isBeforeBossPhase = false; | ||
|
||
private bool animateText = true; | ||
private int currentIndex = 0; | ||
[Header("Layers to include")] | ||
[SerializeField] private LayerMask includeLayer; | ||
|
||
[Header("Wave Manager Dependencies")] | ||
[SerializeField] private WaveManager waveManager; | ||
|
||
private void Start() | ||
{ | ||
StartConversation(); | ||
StartCoroutine(TypePhrases()); | ||
} | ||
|
||
private void OnTriggerEnter(Collider collision) | ||
{ | ||
if (collision.gameObject.layer == LayerMask.NameToLayer("Player") && Time.timeScale != 0) | ||
if (((Constants.ONE << collision.gameObject.layer) & includeLayer) != Constants.ZERO && Time.timeScale != 0) | ||
{ | ||
animateText = true; | ||
if (waveManager.currentWaveIndex == 14) | ||
{ | ||
_isBeforeBossPhase = true; | ||
} | ||
|
||
StartCoroutine(TypePhrases()); | ||
} | ||
} | ||
|
||
private void OnTriggerExit(Collider collision) | ||
{ | ||
if (collision.gameObject.layer == LayerMask.NameToLayer("Player") && Time.timeScale != 0) | ||
if (((Constants.ONE << collision.gameObject.layer) & includeLayer) != Constants.ZERO && Time.timeScale != 0) | ||
{ | ||
animateText = false; | ||
StopAllCoroutines(); | ||
} | ||
} | ||
|
||
public void StartConversation() | ||
{ | ||
StartCoroutine(AnimateText()); | ||
} | ||
|
||
private IEnumerator AnimateText() | ||
private IEnumerator TypePhrases() | ||
{ | ||
while (animateText) | ||
{ | ||
string currentPhrase = phrases[currentIndex]; | ||
string[] selectedPhrases = _isBeforeBossPhase ? phrasesBeforeBoss : phrases; | ||
|
||
textMeshPro.text = ""; | ||
int index = 0; | ||
|
||
for (int i = 0; i < currentPhrase.Length; i++) | ||
{ | ||
textMeshPro.text += currentPhrase[i]; | ||
|
||
yield return new WaitForSeconds(typingSpeed * Time.deltaTime); | ||
} | ||
while (true) | ||
{ | ||
string phrase = selectedPhrases[index]; | ||
yield return TypePhrase(phrase); | ||
yield return new WaitForSeconds(wordWait); | ||
textMeshPro.text = ""; | ||
|
||
yield return new WaitForSeconds(2f); | ||
index = (index + 1) % selectedPhrases.Length; | ||
} | ||
} | ||
|
||
currentIndex = (currentIndex + 1) % phrases.Length; | ||
private IEnumerator TypePhrase(string phrase) | ||
{ | ||
for (int i = 0; i < phrase.Length; i++) | ||
{ | ||
textMeshPro.text = phrase[..(i + 1)]; | ||
yield return new WaitForSeconds(typingSpeed); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters