using System; using GameOff.Core; using GameOff.Quiz; using UnityEngine; using Random = UnityEngine.Random; namespace GameOff.Peasant { public class PeasantMain : QuizTaker { [SerializeField] private float initTime = 20f; [SerializeField] private float minTimePerQuestion = 5f; [SerializeField] private float maxTimePerQuestion = 18f; [Range(0, 1)] [SerializeField] private float successRate = 0.75f; private int _indexQuestion; private float _answerTimer; protected override void Start() { base.Start(); _answerTimer = initTime + RandomQuestionTimer(); } private void Update() { _answerTimer -= Time.deltaTime; if (_answerTimer <= 0) { SetAnswer(_indexQuestion, QuizHandler.Instance.GetAnswerAtIndex(_indexQuestion, successRate)); _answerTimer = RandomQuestionTimer(); _indexQuestion++; if (_indexQuestion >= answers.Length) { Debug.Log($"{name}: {QuizHandler.Instance.GetResultPercent(answers)}%"); enabled = false; } } } private float RandomQuestionTimer() { return Random.Range(minTimePerQuestion, maxTimePerQuestion); } } }