1
00:00:03,710 --> 00:00:09,530
Now that we have our script for objects storing our question data, it's time to connect them to the

2
00:00:09,530 --> 00:00:10,250
UI.

3
00:00:11,570 --> 00:00:17,420
So the first thing we want to do before we can connect these up is to create a new script and we're

4
00:00:17,420 --> 00:00:20,080
going to create the script on the quiz canvas.

5
00:00:20,090 --> 00:00:25,910
So let's scroll down in the inspector and add a new component and we'll call this new script quiz.

6
00:00:26,000 --> 00:00:32,450
So this script is going to handle the majority of our game logic and keep our assets folder tidy.

7
00:00:32,450 --> 00:00:36,200
Let's move our quiz script into the scripts folder.

8
00:00:37,470 --> 00:00:41,370
Now let's go ahead and open up this quiz CSS script.

9
00:00:42,670 --> 00:00:47,980
And the first thing I like to do in any new script is to just delete these comments above, start an

10
00:00:47,980 --> 00:00:52,120
update, because once we've been using nudity for a while, we don't really need them and they're just

11
00:00:52,120 --> 00:00:54,310
taking up space and causing clutter.

12
00:00:54,700 --> 00:00:58,960
And whilst we may need it later, we're not actually going to need the update method for now.

13
00:00:58,960 --> 00:01:02,830
So let's clear that out as well, just to keep our script as tidy as possible.

14
00:01:03,520 --> 00:01:08,740
Now, with all that set up, let's think about how we're going to get the question text out of our script

15
00:01:08,800 --> 00:01:11,200
or object and onto the canvas.

16
00:01:11,620 --> 00:01:16,930
Well, the first thing we're going to want is a variable to hold the script or object that we're working

17
00:01:16,930 --> 00:01:17,410
with.

18
00:01:17,710 --> 00:01:22,330
So let's create that variable, and this variable will be a type question.

19
00:01:22,390 --> 00:01:28,660
So, so just like we can have variables for things like strings and integers, we can also have variables

20
00:01:28,660 --> 00:01:31,210
that relate to the name of another script.

21
00:01:31,810 --> 00:01:35,050
And we'll go ahead and call this question for now.

22
00:01:35,590 --> 00:01:41,650
And for the access level, personally, I really do prefer to keep all of my variables private unless

23
00:01:41,650 --> 00:01:43,300
I need extra access.

24
00:01:43,330 --> 00:01:48,970
In this case, we're not currently accessing this from anywhere else in our code, but we will need

25
00:01:48,970 --> 00:01:52,600
to still be able to set this script to object in the inspector.

26
00:01:52,630 --> 00:01:58,140
So rather than leaving it as a private variable, let's upgrade it to a serialized field for now.

27
00:01:58,150 --> 00:02:03,280
And if it turns out that we need this information in another script later on, we can always come back

28
00:02:03,280 --> 00:02:04,450
and make it public.

29
00:02:05,240 --> 00:02:10,310
The next thing we're going to need access to is the text element on our canvas.

30
00:02:10,550 --> 00:02:14,930
And to do this, we're going to have to add something to the very top of our script, where we have

31
00:02:14,930 --> 00:02:20,960
all of these using statements and all these using statements really do is just controls what code our

32
00:02:20,960 --> 00:02:22,730
script currently has access to.

33
00:02:22,910 --> 00:02:28,250
Now we're going to need access to the text message pro element on our UI canvas.

34
00:02:28,250 --> 00:02:35,210
So let's add the using statement t m pro and the capitalization is important here.

35
00:02:35,210 --> 00:02:41,660
So we have capital tmp and then the lowercase row at the end there and this will open some additional

36
00:02:41,660 --> 00:02:42,710
options for us.

37
00:02:43,130 --> 00:02:49,400
So let's create another new variable to store a reference to this text mesh pro object on our canvas.

38
00:02:49,700 --> 00:02:54,500
And this is going to be a type text mesh pro u gooey.

39
00:02:54,680 --> 00:02:56,570
So as we start typing, we'll see.

40
00:02:56,570 --> 00:02:59,210
The IntelliSense gives us two options.

41
00:02:59,210 --> 00:03:05,870
We have a text mesh pro, which is predominantly for text that's actually existing in our game world

42
00:03:05,870 --> 00:03:11,120
and text mesh pro you gooey, which is for any UI based text.

43
00:03:11,120 --> 00:03:13,970
So the one we want here is our UI based text.

44
00:03:13,970 --> 00:03:16,820
So let's pick text mesh pro-EU gooey.

45
00:03:17,300 --> 00:03:19,790
Then we need to give our variable a name.

46
00:03:19,790 --> 00:03:22,190
So let's call this the question text.

47
00:03:23,490 --> 00:03:28,830
And again, for the access level, we are going to need to set this in the inspector.

48
00:03:28,860 --> 00:03:31,980
So let's just go ahead and make it a serialized field.

49
00:03:32,610 --> 00:03:37,320
And again, if we need to change the access later on to make it more public, then we can come back

50
00:03:37,320 --> 00:03:38,010
and do that.

51
00:03:38,650 --> 00:03:40,180
So there are two main variables.

52
00:03:40,180 --> 00:03:46,060
We're going to have a reference to the question and a reference to the text element on our canvas and

53
00:03:46,060 --> 00:03:47,890
that we need to connect the two.

54
00:03:48,560 --> 00:03:54,440
So let's very quickly pop back over into our script to object because we did create some getter methods

55
00:03:54,440 --> 00:03:55,220
in here.

56
00:03:55,490 --> 00:03:59,510
So what we're trying to do is we're trying to return this question string.

57
00:03:59,840 --> 00:04:02,510
And we can do that with this get question method.

58
00:04:02,930 --> 00:04:05,930
So jump back over into our quiz script.

59
00:04:06,320 --> 00:04:11,360
And we're going to say that the question text, dot text.

60
00:04:12,240 --> 00:04:18,720
This going to set the text field of our text mesh object on the canvas and we're going to set that equal

61
00:04:18,750 --> 00:04:23,310
to be the question dot get question.

62
00:04:25,680 --> 00:04:28,860
So let's save up our script and see what this does.

63
00:04:29,130 --> 00:04:31,200
Let's jump back over into unity.

64
00:04:31,960 --> 00:04:33,580
And wait for things to compile.

65
00:04:34,360 --> 00:04:39,520
And now if we go ahead and click on our quiz canvas and scroll down to see our quiz script that we've

66
00:04:39,520 --> 00:04:44,260
just written, we need to fill in the question text from our UI.

67
00:04:44,290 --> 00:04:50,830
So let's just drag that over from the hierarchy into question text, and we need a question to add to

68
00:04:50,830 --> 00:04:51,770
our canvas.

69
00:04:51,790 --> 00:04:56,950
Now, we're currently only worrying about one single question rather than the whole array of questions

70
00:04:56,950 --> 00:04:58,330
that we have at the moment.

71
00:04:58,780 --> 00:05:04,480
So let's go over to our questions folder and pick any one of our scriptural objects for now and drop

72
00:05:04,480 --> 00:05:06,200
that into the question field.

73
00:05:06,220 --> 00:05:12,610
And now if we go ahead and hit play, we should see this lorem ipsum text change to the text from our

74
00:05:12,610 --> 00:05:13,330
question.

75
00:05:14,780 --> 00:05:15,470
And here we go.

76
00:05:15,470 --> 00:05:19,520
We've now got the question displaying correctly when we're in play mode.

77
00:05:19,790 --> 00:05:22,910
So that puts us one step closer to our final game.

78
00:05:22,910 --> 00:05:24,620
And that's going to be all for this lecture.

79
00:05:24,620 --> 00:05:26,420
Quite a short and sweet one.

80
00:05:26,420 --> 00:05:31,490
But in the next lecture, we're going to follow a similar kind of process and connect all of the answers

81
00:05:31,490 --> 00:05:32,930
to our buttons.

82
00:05:32,930 --> 00:05:34,340
So I'll see you there.

