- Home /
Other : Asking for Scripts
Creating a Multiple Choice Game
im creating a game that will make a multiple choice question will pop up while playing but i dont have and idea on how to do it may because im really new at coding and im really dumb at it but im willing to learn so please help me and give me an example code/script for what i want to do and i promise that i will study it by the way this is for my thesis project and i really need to finish it to graduate so advance thanks for anyone who's willing to help me i just nid a sample code because i dont know how to do it from scratch thankyou
Answer by KellyThomas · Jan 27, 2014 at 01:12 AM
No one will want to do your homework for you but people will probably offer some advice and guidance along the way.
The first thing to do is break down a project into a series of manageable tasks. You can then focus on building a each small part, and slowly expand until you have built the whole.
A multiple choice game is really a series of individual questions (with a running tally for score).
Each question takes the form of a passage of text (the question) and several other passages of text (the answers) for the player to choose from.
I would recommend using Unity's GUI tools to implement this, the question could be a label
and each answer could be a button
.
I think you will find everything you need to know to implement an individual question over here in the documentation.
First build the code to:
Display the question
then the buttons
determine if the answer was correct
Once you have that up and running please come back here and ask more focused questions if/when you encounter specific problems.
Sir i code a script where in when you press the button a label with another button will appear but what happens is when you click the object where you put the script thats where it pop up so i want it to pop up in when you press the button and not the object please help me again thank you using UnityEngine; using System.Collections; public class Attack : $$anonymous$$onoBehaviour { // Use this for initialization private bool Poop; public string Info; void On$$anonymous$$ouseDown() { Poop = true; } void DrawInfo() { Rect rect = new Rect (600,500, 200, 100); Rect close = new Rect (10,20,200,200); if (Poop) { GUI.Box(rect, Info); if (GUI.Button(close,"X")) { Poop = false; } } } void OnGUI() { DrawInfo(); } }
Well the On$$anonymous$$ouseDown()
method is intended to behave like that, it may not meet your needs.
You could try this implementation, it has a couple of changes so that:
the close button is always drawn
the close button now toggles the
Box
's visibility on and off.
.
void DrawInfo() {
Rect rect = new Rect (600,500, 200, 100);
Rect close = new Rect (10,20,200,200);
if (GUI.Button(close,"X")) {
Poop = !Poop;
}
if (Poop) {
GUI.Box(rect, Info);
}
}
thanks bro you really solved my problem anyway i already did two of the things you told me
1.Display the question 2.then the buttons
can you help me for another problem, how can i randomize the question that will be show'n every time that i push the button here's the code that ive done anyway thanks a lot for your help
using UnityEngine;
using System.Collections;
public class wawa : $$anonymous$$onoBehaviour {
// Use this for initialization
private bool Poop;
public string Info;
void On$$anonymous$$ouseDown()
{
Poop = true;
}
void DrawInfo()
{
Rect rect = new Rect (500,100, 400,200);
Rect close = new Rect (600,500,200,100);
if (GUI.Button(close,"ATTAC$$anonymous$$")) {
Poop = !Poop;
}
if (Poop) {
GUI.Box(rect, Info);
GUI.Label(new Rect (520, 110, 400, 30), "QUESTION");
GUI.Button (new Rect (520, 200, 100, 30), "A");
GUI.Button (new Rect (520, 250, 100, 30), "B");
GUI.Button (new Rect (780, 200, 100, 30), "C");
GUI.Button (new Rect (780, 250, 100, 30), "D");
//GUI.Label (Rect (0,0,100,50), "This is the text string for a Label Control");
}
}
void OnGUI()
{
DrawInfo();
}
}
The best approach depends a little bit on how you want things laid out.
Do you want it with the answers included in the question string, so it looks like this:
What in the Capital of France:
A) Paris
B) New York
C) London
D) $$anonymous$$adrid
[ A ] [ B ]
[ C ] [ D ]
You do you want the answers on the buttons, so it looks like this:
What in the Capital of France?
[ Paris ] [ New York ]
[ London ] [ $$anonymous$$adrid ]
Do you want the questions written in your code? or loaded from a text file?
The first layout and the question written in the code are the easiest to get working but it's best to clarify requirements up front.
Follow this Question
Related Questions
Multiple Choice game in Unity 0 Answers
Best way to make a Quiz system? 0 Answers
Make quiz game Confused About PlayerPrefs and database 1 Answer
Instantiate a 2d Pop up 1 Answer
What does Mecanim DO? 3 Answers