From 99942f4b0716a9424572754dceb94799158c79bb Mon Sep 17 00:00:00 2001 From: nicorm2000 Date: Tue, 5 Mar 2024 21:42:58 -0300 Subject: [PATCH] Finally fixed conversation --- Assets/Scenes/Level.unity | 21 ++++-- Assets/Scripts/Level Objejcts/Conversation.cs | 65 +++++++++++-------- ProjectSettings/ProjectSettings.asset | 3 +- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Assets/Scenes/Level.unity b/Assets/Scenes/Level.unity index 18d22a88..28042115 100644 --- a/Assets/Scenes/Level.unity +++ b/Assets/Scenes/Level.unity @@ -3126,7 +3126,7 @@ GameObject: - component: {fileID: 134319938} - component: {fileID: 134319937} m_Layer: 5 - m_Name: phrases + m_Name: Phrases m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -3173,15 +3173,15 @@ MonoBehaviour: m_Calls: [] m_text: m_isRightToLeft: 0 - m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontAsset: {fileID: 11400000, guid: c1431d80935cee34b9fd4113e7d94866, type: 2} + m_sharedMaterial: {fileID: 8233435915380040242, guid: c1431d80935cee34b9fd4113e7d94866, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] m_fontColor32: serializedVersion: 2 rgba: 4278190080 - m_fontColor: {r: 0, g: 0, b: 0, a: 1} + m_fontColor: {r: 1, g: 1, b: 1, a: 1} m_enableVertexGradient: 0 m_colorMode: 3 m_fontColorGradient: @@ -38472,11 +38472,22 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: textMeshPro: {fileID: 134319937} - typingSpeed: 10 + typingSpeed: 0.1 + wordWait: 2 phrases: - Hey, this is the shop! - Please, choose your next weapon! - Let the carnage begin! + phrasesBeforeBoss: + - Pick your last weapon! + - You will face the biggest of threats! + - The Tako monster isn't a nobody! + - I wish for the best luck against him! + - Stay safe! Stay juicy! Stay tasty! + includeLayer: + serializedVersion: 2 + m_Bits: 64 + waveManager: {fileID: 760154691} --- !u!65 &1759705848 BoxCollider: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Level Objejcts/Conversation.cs b/Assets/Scripts/Level Objejcts/Conversation.cs index bf68db77..140ff138 100644 --- a/Assets/Scripts/Level Objejcts/Conversation.cs +++ b/Assets/Scripts/Level Objejcts/Conversation.cs @@ -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); } } } \ No newline at end of file diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 04b82137..797fb14f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -140,8 +140,7 @@ PlayerSettings: vulkanEnableCommandBufferRecycling: 1 loadStoreDebugModeEnabled: 0 bundleVersion: 1.0.0 - preloadedAssets: - - {fileID: 11400000, guid: c67baedd11d560a47aec82faf0b5abef, type: 2} + preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1