feature: Added progress bar
This commit is contained in:
parent
60fd82cff5
commit
a4a6cccc6c
4 changed files with 67 additions and 8 deletions
29
Assets/Scripts/Flow/ProgressBar.cs
Normal file
29
Assets/Scripts/Flow/ProgressBar.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Flow/ProgressBar.cs.meta
Normal file
11
Assets/Scripts/Flow/ProgressBar.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bbbaf5b51c023404885d2bbb502c3276
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue