Commit a4a6cccc authored by Gerard Gascón's avatar Gerard Gascón
Browse files

feature: Added progress bar

parent 60fd82cf
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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
+29 −0
Original line number Diff line number Diff line
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;
		}
	}
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: bbbaf5b51c023404885d2bbb502c3276
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+12 −8
Original line number Diff line number Diff line
@@ -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
					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);
			if (!isCorrect) {
				yield return ModifyMessageText(_currentJoke.AnswerMessage.Key, _messages.Length - 1, true, false);
			}
			yield return ModifyRealMessageText(_currentJoke.AnswerMessage.Value, _messages.Length - 1, true);
		}