Skip to content

Commit

Permalink
Fix lifeline bug
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-keogh committed Mar 23, 2021
1 parent ad78599 commit f400640
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Assets/__Scripts/UI/AnswerButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class AnswerButton : MonoBehaviour
private SoundController sc;
private List<AnswerButton> answerButtons;

public Answer AnswerValue => answerValue;
public bool IsDisabled => isDisabled;

void Start()
{
gc = FindObjectOfType<GameController>();
Expand Down
15 changes: 14 additions & 1 deletion Assets/__Scripts/UI/LifelinesUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using OpenTDB;
Expand Down Expand Up @@ -121,7 +122,19 @@ private string GetLifelineAnswer()
}
else
{
return Enum.RandomValue<Answer>().ToString();
// Get a random (and not disabled) answer
var buttons = FindObjectsOfType<AnswerButton>();

do
{
Answer value = Enum.RandomValue<Answer>();
AnswerButton button = buttons.First(b => b.AnswerValue == value);

if (!button.IsDisabled)
{
return value.ToString();
}
} while (true);
}
}

Expand Down

0 comments on commit f400640

Please sign in to comment.