Skip to content

Commit

Permalink
New Update
Browse files Browse the repository at this point in the history
Added
- Category Selection Menu
- 3 new categories to select from
- No question repetation
- Game Complete after anwsering all question in time
  • Loading branch information
swapnilrane24 committed Apr 30, 2020
1 parent fc358b6 commit 722fe9c
Show file tree
Hide file tree
Showing 9 changed files with 1,076 additions and 104 deletions.
918 changes: 835 additions & 83 deletions Assets/Quiz/GameScene.unity

Large diffs are not rendered by default.

Binary file added Assets/Quiz/PassionOne-Regular.ttf
Binary file not shown.
22 changes: 22 additions & 0 deletions Assets/Quiz/PassionOne-Regular.ttf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Assets/Quiz/Resources/AnimalData.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f611d797432e3f846885b2b12fde5f35, type: 3}
m_Name: AnimalData
m_EditorClassIdentifier:
questions:
- questionInfo: Which animal eats Deer?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Lion
- Elephant
- Goat
- Monkey
correctAns: Lion
- questionInfo: Which animal can climb trees?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Zebra
- Bear
- Hyna
- Monkey
correctAns: Monkey
- questionInfo: Which of the following animal is Herbivorous?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Crocodile
- Moose
- Bear
- Panther
correctAns: Moose
- questionInfo: Who can walk on 2 legs?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Dog
- Cat
- Human
- Turtle
correctAns: Human
- questionInfo: Slowest animal on the earth?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Cheeta
- Sloth
- Leapord
- Tortois
correctAns: Sloth
8 changes: 8 additions & 0 deletions Assets/Quiz/Resources/AnimalData.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Assets/Quiz/Resources/BirdData.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f611d797432e3f846885b2b12fde5f35, type: 3}
m_Name: BirdData
m_EditorClassIdentifier:
questions:
- questionInfo: What is the fastest bird on two legs?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Chicken
- Ostrich
- Kiwi
- Crow
correctAns: Ostrich
- questionInfo: What is New Zealand's national bird?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Kiwi
- Penguins
- Bat
- Duck
correctAns: Kiwi
- questionInfo: Which bird can't walk on legs?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Capon
- Ravens
- Hummingbird
- Bluebird
correctAns: Hummingbird
- questionInfo: Which bird cannot fly?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Chicken
- Crow
- Sparrow
- Owl
correctAns: Chicken
- questionInfo: Emperor, Rock Hopper and jackass are all types of what?
questionType: 0
questionImage: {fileID: 0}
audioClip: {fileID: 0}
videoClip: {fileID: 0}
options:
- Dodo
- Penguins
- Albatross
- Crow
correctAns: Penguins
8 changes: 8 additions & 0 deletions Assets/Quiz/Resources/BirdData.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 45 additions & 17 deletions Assets/Quiz/Scripts/QuizGameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public class QuizGameUI : MonoBehaviour
[SerializeField] private QuizManager quizManager; //ref to the QuizManager script
[SerializeField] private Text scoreText, timerText;
[SerializeField] private List<Image> lifeImageList;
[SerializeField] private GameObject gameOverPanel;
[SerializeField] private GameObject gameOverPanel, mainMenu, gamePanel;
[SerializeField] private Color correctCol, wrongCol, normalCol; //color of buttons
[SerializeField] private Image questionImg; //image component to show image
[SerializeField] private UnityEngine.Video.VideoPlayer questionVideo; //to show video
[SerializeField] private AudioSource questionAudio; //audio source for audio clip
[SerializeField] private Text questionInfoText; //text to show question
[SerializeField] private List<Button> options; //options button reference
[SerializeField] private List<Button> uiButtons;
#pragma warning restore 649

private float audioLength; //store audio length
Expand All @@ -35,6 +36,11 @@ private void Start()
localBtn.onClick.AddListener(() => OnClick(localBtn));
}

for (int i = 0; i < uiButtons.Count; i++)
{
Button localBtn = uiButtons[i];
localBtn.onClick.AddListener(() => OnClick(localBtn));
}

}
/// <summary>
Expand Down Expand Up @@ -133,26 +139,48 @@ IEnumerator PlayAudio()
/// <param name="btn">ref to the button object</param>
void OnClick(Button btn)
{
//if answered is false
if (!answered)
if (quizManager.GameStatus == GameStatus.PLAYING)
{
//set answered true
answered = true;
//get the bool value
bool val = quizManager.Answer(btn.name);

//if its true
if (val)
{
//set color to correct
btn.image.color = correctCol;
}
else
//if answered is false
if (!answered)
{
//else set it to wrong color
btn.image.color = wrongCol;
//set answered true
answered = true;
//get the bool value
bool val = quizManager.Answer(btn.name);

//if its true
if (val)
{
//set color to correct
btn.image.color = correctCol;
}
else
{
//else set it to wrong color
btn.image.color = wrongCol;
}
}
}

switch (btn.name)
{
case "Animal":
quizManager.StartGame(0);
mainMenu.SetActive(false);
gamePanel.SetActive(true);
break;
case "Bird":
quizManager.StartGame(1);
mainMenu.SetActive(false);
gamePanel.SetActive(true);
break;
case "Mix":
quizManager.StartGame(2);
mainMenu.SetActive(false);
gamePanel.SetActive(true);
break;
}
}

public void RestryButton()
Expand Down
22 changes: 18 additions & 4 deletions Assets/Quiz/Scripts/QuizManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class QuizManager : MonoBehaviour
//ref to the QuizGameUI script
[SerializeField] private QuizGameUI quizGameUI;
//ref to the scriptableobject file
[SerializeField] private QuizDataScriptable dataScriptable;
[SerializeField] private List<QuizDataScriptable> quizDataList;
[SerializeField] private float timeInSeconds;
#pragma warning restore 649
//questions data
Expand All @@ -19,16 +19,20 @@ public class QuizManager : MonoBehaviour
private int gameScore;
private int lifesRemaining;
private float currentTime;
private QuizDataScriptable dataScriptable;

private GameStatus gameStatus = GameStatus.NEXT;

private void Start()
public GameStatus GameStatus { get { return gameStatus; } }

public void StartGame(int categoryIndex)
{
gameScore = 0;
lifesRemaining = 3;
currentTime = timeInSeconds;
//set the questions data
questions = new List<Question>();
dataScriptable = quizDataList[categoryIndex];
questions.AddRange(dataScriptable.questions);
//select the question
SelectQuestion();
Expand All @@ -46,6 +50,8 @@ private void SelectQuestion()
selectedQuetion = questions[val];
//send the question to quizGameUI
quizGameUI.SetQuestion(selectedQuetion);

questions.RemoveAt(val);
}

private void Update()
Expand Down Expand Up @@ -103,8 +109,16 @@ public bool Answer(string selectedOption)

if (gameStatus == GameStatus.PLAYING)
{
//call SelectQuestion method again after 1s
Invoke("SelectQuestion", 0.4f);
if (questions.Count > 0)
{
//call SelectQuestion method again after 1s
Invoke("SelectQuestion", 0.4f);
}
else
{
gameStatus = GameStatus.NEXT;
quizGameUI.GameOverPanel.SetActive(true);
}
}
//return the value of correct bool
return correct;
Expand Down

0 comments on commit 722fe9c

Please sign in to comment.