diff --git a/Assets/Prefabs/NPC.prefab b/Assets/Prefabs/Peasant.prefab similarity index 91% rename from Assets/Prefabs/NPC.prefab rename to Assets/Prefabs/Peasant.prefab index 49510a6..fabc51d 100644 --- a/Assets/Prefabs/NPC.prefab +++ b/Assets/Prefabs/Peasant.prefab @@ -9,8 +9,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 3614258387417921825} + - component: {fileID: 774219910790536021} m_Layer: 0 - m_Name: NPC + m_Name: Peasant m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -32,6 +33,22 @@ Transform: - {fileID: 716864403826928654} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &774219910790536021 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2684113167729998087} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c6861fab896dc3b44bad96b7fb1e4891, type: 3} + m_Name: + m_EditorClassIdentifier: + answers: [] + initTime: 20 + minTimePerQuestion: 5 + maxTimePerQuestion: 18 --- !u!1 &5739709613417327085 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/NPC.prefab.meta b/Assets/Prefabs/Peasant.prefab.meta similarity index 100% rename from Assets/Prefabs/NPC.prefab.meta rename to Assets/Prefabs/Peasant.prefab.meta diff --git a/Assets/Scenes/Samir.unity b/Assets/Scenes/Samir.unity index 98bc285..68d12f6 100644 --- a/Assets/Scenes/Samir.unity +++ b/Assets/Scenes/Samir.unity @@ -237,7 +237,7 @@ GameObject: m_Component: - component: {fileID: 54002814} m_Layer: 0 - m_Name: NPCs + m_Name: Peasant m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -264,7 +264,6 @@ Transform: - {fileID: 266640701} - {fileID: 187840932} - {fileID: 668048816} - - {fileID: 2076373778} m_Father: {fileID: 1958973072} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &81375270 @@ -514,7 +513,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (5) + value: Zoe objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -765,10 +764,25 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 54002814} m_Modifications: + - target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754, + type: 3} + propertyPath: initTime + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754, + type: 3} + propertyPath: maxTimePerQuestion + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754, + type: 3} + propertyPath: minTimePerQuestion + value: 0.5 + objectReference: {fileID: 0} - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (4) + value: Amelia objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -842,7 +856,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (2) + value: Oliver objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -2047,7 +2061,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (7) + value: Caleb objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -3013,7 +3027,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (3) + value: Ethan objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -3371,7 +3385,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (1) + value: Sophia objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -3607,7 +3621,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (8) + value: Layla objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -3880,6 +3894,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 45f6ccbbf842ceb47bfe1cc19085daa0, type: 3} m_Name: m_EditorClassIdentifier: + answers: [] --- !u!114 &1721698432 MonoBehaviour: m_ObjectHideFlags: 0 @@ -3945,6 +3960,7 @@ MonoBehaviour: - {fileID: 233852084, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3} seed: 0 randomGeneration: 1 + correctAnswer: [] --- !u!1 &1839156921 GameObject: m_ObjectHideFlags: 0 @@ -4726,7 +4742,7 @@ PrefabInstance: - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} propertyPath: m_Name - value: NPC (6) + value: Lucas objectReference: {fileID: 0} - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} @@ -4789,80 +4805,6 @@ Transform: type: 3} m_PrefabInstance: {fileID: 2038879509} m_PrefabAsset: {fileID: 0} ---- !u!1001 &2076373777 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 54002814} - m_Modifications: - - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_Name - value: NPC (9) - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalPosition.z - value: 13.25 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalRotation.w - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalRotation.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 180 - objectReference: {fileID: 0} - - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 58a9a466f0501ce4d8388102500b1754, type: 3} ---- !u!4 &2076373778 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - type: 3} - m_PrefabInstance: {fileID: 2076373777} - m_PrefabAsset: {fileID: 0} --- !u!1001 &3500289701967161187 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Quiz/QuizHandler.cs b/Assets/Scripts/Core/QuizHandler.cs similarity index 77% rename from Assets/Scripts/Quiz/QuizHandler.cs rename to Assets/Scripts/Core/QuizHandler.cs index de94496..1998415 100644 --- a/Assets/Scripts/Quiz/QuizHandler.cs +++ b/Assets/Scripts/Core/QuizHandler.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; +using GameOff.Quiz; using UnityEngine; using Random = System.Random; -namespace GameOff.Quiz +namespace GameOff.Core { [DefaultExecutionOrder(-60)] public class QuizHandler : MonoBehaviour @@ -14,7 +15,8 @@ namespace GameOff.Quiz [SerializeField] private List questionVisual; [SerializeField] private int seed; [SerializeField] private bool randomGeneration; - + [SerializeField] private string[] correctAnswer; + private readonly List ChoicePossibles = new List() { "a", "b", "c", "d", "e", "f" }; private Random _random; @@ -44,8 +46,9 @@ namespace GameOff.Quiz private void GenerateQuiz() { _questionInfos = new List(); + correctAnswer = new string[questionAmount]; - for (int i = 1; i <= questionAmount; i++) + for (int i = 0; i < questionAmount; i++) { int amount = _random.Next(2, ChoicePossibles.Count); string answer = ChoicePossibles[_random.Next(amount)]; @@ -53,12 +56,15 @@ namespace GameOff.Quiz for (int x = 0; x < amount; x++) tmp.Add(ChoicePossibles[x]); - _questionInfos.Add(new QuestionInfo(i, questionVisual[_random.Next(questionVisual.Count)], tmp, answer)); + + _questionInfos.Add(new QuestionInfo(i + 1, questionVisual[_random.Next(questionVisual.Count)], tmp, answer)); + correctAnswer[i] = tmp[_random.Next(amount)]; } } + public string GetAnswerAtIndex(int index) => correctAnswer[index]; + public List QuestionInfos => _questionInfos; - public int QuestionAmount => questionAmount; } } diff --git a/Assets/Scripts/Quiz/QuizHandler.cs.meta b/Assets/Scripts/Core/QuizHandler.cs.meta similarity index 100% rename from Assets/Scripts/Quiz/QuizHandler.cs.meta rename to Assets/Scripts/Core/QuizHandler.cs.meta diff --git a/Assets/Scripts/Quiz/QuizTaker.cs b/Assets/Scripts/Core/QuizTaker.cs similarity index 85% rename from Assets/Scripts/Quiz/QuizTaker.cs rename to Assets/Scripts/Core/QuizTaker.cs index 7d06e49..93017a5 100644 --- a/Assets/Scripts/Quiz/QuizTaker.cs +++ b/Assets/Scripts/Core/QuizTaker.cs @@ -1,7 +1,7 @@ -using System; +using GameOff.Quiz; using UnityEngine; -namespace GameOff.Quiz +namespace GameOff.Core { public abstract class QuizTaker: MonoBehaviour { diff --git a/Assets/Scripts/Quiz/QuizTaker.cs.meta b/Assets/Scripts/Core/QuizTaker.cs.meta similarity index 100% rename from Assets/Scripts/Quiz/QuizTaker.cs.meta rename to Assets/Scripts/Core/QuizTaker.cs.meta diff --git a/Assets/Scripts/Peasant.meta b/Assets/Scripts/Peasant.meta new file mode 100644 index 0000000..7f1e70e --- /dev/null +++ b/Assets/Scripts/Peasant.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0d71d71ca8238454fabed5ca071e4807 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Peasant/PeasantMain.cs b/Assets/Scripts/Peasant/PeasantMain.cs new file mode 100644 index 0000000..ee6e771 --- /dev/null +++ b/Assets/Scripts/Peasant/PeasantMain.cs @@ -0,0 +1,46 @@ +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; + + private int _indexQuestion; + private float _answerTimer; + + + protected override void Start() + { + base.Start(); + + _answerTimer = initTime + RandomQuestionTimer(); + } + + private void Update() + { + _answerTimer -= Time.deltaTime; + + if (_answerTimer <= 0) + { + answers[_indexQuestion] = QuizHandler.Instance.GetAnswerAtIndex(_indexQuestion); + _answerTimer = RandomQuestionTimer(); + _indexQuestion++; + + if (_indexQuestion >= answers.Length) + enabled = false; + } + } + + private float RandomQuestionTimer() + { + return Random.Range(minTimePerQuestion, maxTimePerQuestion); + } + } +} diff --git a/Assets/Scripts/Peasant/PeasantMain.cs.meta b/Assets/Scripts/Peasant/PeasantMain.cs.meta new file mode 100644 index 0000000..11a5d5d --- /dev/null +++ b/Assets/Scripts/Peasant/PeasantMain.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6861fab896dc3b44bad96b7fb1e4891 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: