Skip to content

Commit

Permalink
Finally fixed conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicorm2000 committed Mar 6, 2024
1 parent ab433fe commit 99942f4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
21 changes: 16 additions & 5 deletions Assets/Scenes/Level.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
65 changes: 39 additions & 26 deletions Assets/Scripts/Level Objejcts/Conversation.cs
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);
}
}
}
3 changes: 1 addition & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99942f4

Please sign in to comment.