- Home /
Screen utilization
So I am trying to create a simple quiz program. When I test play it within Unity it looks just fine, but when I install it on my phone, it is so small I can hardly see it. Please refer to the picture below. I have tried to use larger text in hopes it would fill in the unused area of the screen but of course that didn't work. How do I tell Unity to use the entire screen? Please see my script below. All I did was to create the scene was drag the Questionnaire2.cs script onto the Main Camera. Any help would be greatly appreciated. Thanks in advance.
====================================
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class Questionnaire2 : MonoBehaviour {
public int questionTextSize;
public int buttonTextSize;
public int buttonWidth;
public int buttonHeight;
public int index;
class Question
{
public string QuestionText;
public List<string> Answers = new List<string>();
public int CorrectAnswer;
}
List<Question> list = new List<Question>();
Question GetQuestion()
{
int rand = Random.Range(0, list.Count);
index = rand;
return list[rand];
}
void OnGUI()
{
//--------------------------For Debug Purposes--------------------------------
//GUI.Label(new Rect(10, 10, 100, 20), "Questions: " + list.Count);
//GUI.Label(new Rect(10, 30, 200, 20), "Current Question: " + index.ToString());
//GUI.Label(new Rect(10, 60, 200, 20), "Current Answers: " + list[index].Answers);
//-----------------------------------------------------------------------------
//Custom setings...
GUI.skin.label.fontSize = questionTextSize;
GUI.skin.button.fontSize = buttonTextSize;
GUI.skin.label.alignment = TextAnchor.UpperCenter;
GUI.skin.label.alignment = TextAnchor.UpperCenter;
//Display question...
GUI.Label(new Rect((Screen.width / 2) - (200 / 2), (Screen.height / 2) - (25 / 2) - 75, 200,200),list[index].QuestionText);
//Display the answers.
for (int i = 0; i <= 3; i++ )
{
if (GUI.Button(new Rect((Screen.width / 2) - (buttonWidth / 2), (Screen.height / 2) - (25 / 2) + i*30, buttonWidth,buttonHeight),list[index].Answers[i]))
{
//If correct answer...
if (i == list[index].CorrectAnswer)
{
Debug.Log("Correct");
if (index < list.Count)
{
list.Remove(list[index]);
GetQuestion();
} //Here we would add the Ending...
else { Debug.LogError("Out Of Questions To Display"); }
}
else //if incorrect....
{
Debug.Log("Incorrect");
GetQuestion();
}
}
}
}
void Awake()
{
//Questions and answers are listed here. Index beginning at 0.
//The CorrectAnswer property should set to the correct
//Index of the correct answer in this first one you can see
//Correct answer is index "3". 0, 1, 2, and 3("Four Text").
list.Add(new Question());
list[0].QuestionText = "What is 2 + 2?";
list[0].Answers.Add("1");
list[0].Answers.Add("2");
list[0].Answers.Add("22");
list[0].Answers.Add("4");
list[0].CorrectAnswer = 3;
list.Add(new Question());
list[1].QuestionText = "What is 4 + 4?";
list[1].Answers.Add("4");
list[1].Answers.Add("44");
list[1].Answers.Add("8");
list[1].Answers.Add("100");
list[1].CorrectAnswer = 2;
list.Add(new Question());
list[2].QuestionText = "What is 6 + 6?";
list[2].Answers.Add("16");
list[2].Answers.Add("9");
list[2].Answers.Add("12");
list[2].Answers.Add("6,000,000");
list[2].CorrectAnswer = 2;
list.Add(new Question());
list[3].QuestionText = "What is 8 + 8?";
list[3].Answers.Add("2");
list[3].Answers.Add("88");
list[3].Answers.Add("5");
list[3].Answers.Add("16");
list[3].CorrectAnswer = 3;
//So to add a new question. Copy a block
//Like this one and paste it below. Then
// Change the text in between ".."
//And increment the number list[4] to list[5]
//and so on... The "3" on Correct answer
//is the index. 0,1,2,3 (or in human 1,2,3,4)
//So the 3 index is where it says
//list[4].Answers.Add("16");
//the "4" is the question's index.
list.Add(new Question());
list[4].QuestionText = "What is 8 + 8?";
list[4].Answers.Add("2");
list[4].Answers.Add("88");
list[4].Answers.Add("5");
list[4].Answers.Add("16");
list[4].CorrectAnswer = 3;
//Get a question at runtime.
GetQuestion();
}
}
====================================
Your answer
Follow this Question
Related Questions
Gizmo-like GUi text? 2 Answers
Fit GUIText in every resolution 3 Answers
GUIText shows only in one camera (not the others) 1 Answer
How to set the position of a guitext using transform? 1 Answer
Print Anything to Screen 4 Answers