feature: Added progress bar

This commit is contained in:
Gerard Gascón 2024-01-28 10:54:56 +01:00
parent 60fd82cff5
commit a4a6cccc6c
4 changed files with 67 additions and 8 deletions

View file

@ -2474,6 +2474,7 @@ GameObject:
- component: {fileID: 1352489079}
- component: {fileID: 1352489078}
- component: {fileID: 1352489077}
- component: {fileID: 1352489081}
m_Layer: 5
m_Name: ProgressCanvas
m_TagString: Untagged
@ -2564,6 +2565,20 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1352489081
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1352489076}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bbbaf5b51c023404885d2bbb502c3276, type: 3}
m_Name:
m_EditorClassIdentifier:
bar: {fileID: 843204721}
numberToWin: 10
--- !u!1 &1488949019
GameObject:
m_ObjectHideFlags: 0

View file

@ -0,0 +1,29 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Flow {
public class ProgressBar : MonoBehaviour {
[SerializeField] private Image bar;
private int _progressDone;
[SerializeField, Min(0)] private int numberToWin = 10;
private void Awake() {
UpdateFill();
}
public void AddProgress() {
_progressDone++;
if (_progressDone <= numberToWin) {
UpdateFill();
}
}
private void UpdateFill() {
float fillPercentage = _progressDone / (float)numberToWin;
bar.fillAmount = fillPercentage;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bbbaf5b51c023404885d2bbb502c3276
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -72,16 +72,18 @@ namespace Messaging {
_currentJokeIndex = Mathf.Max(_currentJokeIndex, 0);
if (message == _currentJoke.AnswerMessage.Key) {
_sendButton.Lock();
Coroutine routine = StartCoroutine(ShowRealTexts());
if(_currentJokeIndex == 0)
StartCoroutine(SendRandomJoke(routine, sendJokeDelay));
else
StartCoroutine(SendRandomJoke(routine, sendJokeDelay));
bool isCorrect = _currentJokeIndex != 0;
Coroutine routine = StartCoroutine(ShowRealTexts(isCorrect));
StartCoroutine(SendRandomJoke(routine, sendJokeDelay));
if (isCorrect) {
FindObjectOfType<ProgressBar>().AddProgress();
}
} else {
_lives.Wrong();
if (_lives.CurrentLives == 0) {
_sendButton.Lock();
Coroutine routine = StartCoroutine(ShowRealTexts());
Coroutine routine = StartCoroutine(ShowRealTexts(false));
StartCoroutine(SendRandomJoke(routine, initialSendJokeDelay));
_lives.ResetLives();
}
@ -91,9 +93,11 @@ namespace Messaging {
}
}
private IEnumerator ShowRealTexts() {
private IEnumerator ShowRealTexts(bool isCorrect) {
yield return ModifyRealMessageText(_currentJoke.QuestionMessage.Value, _currentJokeIndex, false);
yield return ModifyMessageText(_currentJoke.AnswerMessage.Key, _messages.Length - 1, true, false);
if (!isCorrect) {
yield return ModifyMessageText(_currentJoke.AnswerMessage.Key, _messages.Length - 1, true, false);
}
yield return ModifyRealMessageText(_currentJoke.AnswerMessage.Value, _messages.Length - 1, true);
}