Now that we have our script for objects storing our question data, it's time to connect them to the
UI.
So the first thing we want to do before we can connect these up is to create a new script and we're
going to create the script on the quiz canvas.
So let's scroll down in the inspector and add a new component and we'll call this new script quiz.
So this script is going to handle the majority of our game logic and keep our assets folder tidy.
Let's move our quiz script into the scripts folder.
Now let's go ahead and open up this quiz CSS script.
And the first thing I like to do in any new script is to just delete these comments above, start an
update, because once we've been using nudity for a while, we don't really need them and they're just
taking up space and causing clutter.
And whilst we may need it later, we're not actually going to need the update method for now.
So let's clear that out as well, just to keep our script as tidy as possible.
Now, with all that set up, let's think about how we're going to get the question text out of our script
or object and onto the canvas.
Well, the first thing we're going to want is a variable to hold the script or object that we're working
with.
So let's create that variable, and this variable will be a type question.
So, so just like we can have variables for things like strings and integers, we can also have variables
that relate to the name of another script.
And we'll go ahead and call this question for now.
And for the access level, personally, I really do prefer to keep all of my variables private unless
I need extra access.
In this case, we're not currently accessing this from anywhere else in our code, but we will need
to still be able to set this script to object in the inspector.
So rather than leaving it as a private variable, let's upgrade it to a serialized field for now.
And if it turns out that we need this information in another script later on, we can always come back
and make it public.
The next thing we're going to need access to is the text element on our canvas.
And to do this, we're going to have to add something to the very top of our script, where we have
all of these using statements and all these using statements really do is just controls what code our
script currently has access to.
Now we're going to need access to the text message pro element on our UI canvas.
So let's add the using statement t m pro and the capitalization is important here.
So we have capital tmp and then the lowercase row at the end there and this will open some additional
options for us.
So let's create another new variable to store a reference to this text mesh pro object on our canvas.
And this is going to be a type text mesh pro u gooey.
So as we start typing, we'll see.
The IntelliSense gives us two options.
We have a text mesh pro, which is predominantly for text that's actually existing in our game world
and text mesh pro you gooey, which is for any UI based text.
So the one we want here is our UI based text.
So let's pick text mesh pro-EU gooey.
Then we need to give our variable a name.
So let's call this the question text.
And again, for the access level, we are going to need to set this in the inspector.
So let's just go ahead and make it a serialized field.
And again, if we need to change the access later on to make it more public, then we can come back
and do that.
So there are two main variables.
We're going to have a reference to the question and a reference to the text element on our canvas and
that we need to connect the two.
So let's very quickly pop back over into our script to object because we did create some getter methods
in here.
So what we're trying to do is we're trying to return this question string.
And we can do that with this get question method.
So jump back over into our quiz script.
And we're going to say that the question text, dot text.
This going to set the text field of our text mesh object on the canvas and we're going to set that equal
to be the question dot get question.
So let's save up our script and see what this does.
Let's jump back over into unity.
And wait for things to compile.
And now if we go ahead and click on our quiz canvas and scroll down to see our quiz script that we've
just written, we need to fill in the question text from our UI.
So let's just drag that over from the hierarchy into question text, and we need a question to add to
our canvas.
Now, we're currently only worrying about one single question rather than the whole array of questions
that we have at the moment.
So let's go over to our questions folder and pick any one of our scriptural objects for now and drop
that into the question field.
And now if we go ahead and hit play, we should see this lorem ipsum text change to the text from our
question.
And here we go.
We've now got the question displaying correctly when we're in play mode.
So that puts us one step closer to our final game.
And that's going to be all for this lecture.
Quite a short and sweet one.
But in the next lecture, we're going to follow a similar kind of process and connect all of the answers
to our buttons.
So I'll see you there.