Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,580 --> 00:00:10,360
Now we want to add some kind of a game mechanic to this, so game mechanics are almost like the rules
2
00:00:10,360 --> 00:00:17,590
or the gameplay element that makes it addictive and makes it kind of fun and interactive.
3
00:00:18,130 --> 00:00:24,970
And in this one where we're going to add a timer, so you get maybe 30 seconds and you have to survive
4
00:00:24,970 --> 00:00:29,830
for 30 seconds against an endless loop of enemies.
5
00:00:30,220 --> 00:00:35,950
And if you manage to make it to 30 seconds, then it will load the next level.
6
00:00:36,620 --> 00:00:40,960
OK, and the whole idea behind this game is you've got to see how many levels you can achieve.
7
00:00:41,560 --> 00:00:42,850
It's almost like Tetris.
8
00:00:43,630 --> 00:00:48,910
You know, in Tetris, it keeps getting faster and faster and faster each level you go up.
9
00:00:49,150 --> 00:00:50,920
So you just see how long you can survive.
10
00:00:51,550 --> 00:00:54,790
Now, that's kind of the idea that I want to put into this game.
11
00:00:55,360 --> 00:00:59,500
So, first of all, we need some kind of text at the top, and this is going to be on that canvas.
12
00:01:00,100 --> 00:01:02,270
So I'm going to right click UI.
13
00:01:02,350 --> 00:01:07,320
And that some text now probably be somewhere in the center of the screen and really odd to see.
14
00:01:07,330 --> 00:01:09,340
So I'm just going to change the color to white.
15
00:01:10,300 --> 00:01:13,990
And I'm going to change the size to maybe about 80.
16
00:01:15,310 --> 00:01:18,190
And then I'm just going to move this up.
17
00:01:18,460 --> 00:01:19,060
There it is.
18
00:01:20,890 --> 00:01:22,240
Just click and drag on the Y.
19
00:01:26,420 --> 00:01:33,850
And then I'm going to click on the alignment center so I can get it centered on the screen.
20
00:01:35,380 --> 00:01:36,490
And this is just goodness.
21
00:01:36,790 --> 00:01:39,520
Let's say that we give around 30 seconds.
22
00:01:39,530 --> 00:01:44,260
Yeah, my font style might actually make that bold, just so it stands out a little bit more.
23
00:01:44,830 --> 00:01:45,220
OK.
24
00:01:45,540 --> 00:01:48,940
And we're going to be controlling this text through code.
25
00:01:50,350 --> 00:01:53,950
So I'll just rename this time of text.
26
00:01:56,650 --> 00:02:01,150
So now in our script, in the main script, we're going to
27
00:02:03,970 --> 00:02:07,840
leave ourselves and a comment, so I'll call a timer.
28
00:02:08,680 --> 00:02:19,540
And first of all, we need a public offsite text or call timer, then a public integer.
29
00:02:20,320 --> 00:02:24,250
I'm going to call level time limit.
30
00:02:24,870 --> 00:02:35,470
And to make that equal, about 30 and then a private integer we'll call level current time.
31
00:02:38,660 --> 00:02:44,190
Keep, keep, keep a record of exactly how many seconds have passed by.
32
00:02:44,880 --> 00:02:48,210
And now this is one of the reasons why we've got this time countdown.
33
00:02:48,600 --> 00:02:55,410
Instead of doing this every frame, we know that we only want the time to go down each and every second.
34
00:02:55,830 --> 00:03:02,730
So we're using a one second coroutine or a one second pulse that avoids overloading our update method
35
00:03:03,450 --> 00:03:06,480
and with unnecessary commands.
36
00:03:06,660 --> 00:03:12,240
OK, so we can use our time countdown where we have time.
37
00:03:12,240 --> 00:03:15,000
Countdown to his start in the coroutine time delay.
38
00:03:15,690 --> 00:03:20,880
OK, well, we actually want to make sure that only happens as long as time is greater than zero.
39
00:03:21,090 --> 00:03:27,540
So we can say if the level of time is greater than zero.
40
00:03:30,490 --> 00:03:34,390
And run this custom function.
41
00:03:35,590 --> 00:03:35,950
OK.
42
00:03:35,980 --> 00:03:40,240
However, we do also need to ensure that we're taking time off.
43
00:03:41,710 --> 00:03:42,430
Current time.
44
00:03:42,790 --> 00:03:50,500
So we're going to stay level current time minus equals one each time this runs, and this runs once
45
00:03:50,500 --> 00:03:51,190
per second.
46
00:03:52,360 --> 00:03:55,870
And then we also need to update our text as well.
47
00:03:55,900 --> 00:03:57,640
So I'm going to say timer.
48
00:03:57,880 --> 00:04:06,400
So text lowercase equals level current time.
49
00:04:08,320 --> 00:04:08,630
OK.
50
00:04:08,660 --> 00:04:09,920
And if I leave it at that.
51
00:04:09,940 --> 00:04:12,640
Notice that I get this red squiggle.
52
00:04:13,030 --> 00:04:16,420
So you cannot implicitly convert time integer to string.
53
00:04:16,930 --> 00:04:17,200
All right.
54
00:04:17,230 --> 00:04:18,850
String this basically just text.
55
00:04:19,270 --> 00:04:22,150
So we do dot to string.
56
00:04:23,050 --> 00:04:28,750
And that will then convert it, OK, into an into actual text.
57
00:04:29,680 --> 00:04:33,940
Now we need to essentially say if.
58
00:04:34,670 --> 00:04:35,830
Level current time
59
00:04:38,470 --> 00:04:41,530
is less than or equal to zero.
60
00:04:41,920 --> 00:04:44,020
Not not case for now.
61
00:04:44,290 --> 00:04:47,230
We're just going to pause the game to make sure it works.
62
00:04:47,560 --> 00:04:50,230
So when you say time, double time scale.
63
00:04:52,990 --> 00:04:54,190
Equals zero.
64
00:04:54,670 --> 00:04:56,980
OK, and that will effectively just pause the game.
65
00:04:58,810 --> 00:05:00,310
So let's save this.
66
00:05:03,250 --> 00:05:04,360
Wait for that to compile.
67
00:05:08,210 --> 00:05:14,150
And then, you know, our main script, we should now have a time, a text, let's drag in that time
68
00:05:14,150 --> 00:05:14,780
a text.
69
00:05:15,950 --> 00:05:16,490
There we go.
70
00:05:16,700 --> 00:05:18,760
And we know that we're running on about 30.
71
00:05:18,770 --> 00:05:23,180
So let's just try this and make sure that that time is actually going down.
72
00:05:31,730 --> 00:05:32,120
OK.
73
00:05:32,720 --> 00:05:40,610
And now and at the moment, it pulls the game for some reason.
74
00:05:41,690 --> 00:05:43,580
Let me see if Lovel caught on tape.
75
00:05:44,600 --> 00:05:45,220
OK, what is.
76
00:05:45,220 --> 00:05:46,070
Second, wait a second.
77
00:05:46,430 --> 00:05:49,730
Yeah, I need to make in the start.
78
00:05:49,730 --> 00:05:53,690
I need to make my level current time equal my level time limit.
79
00:05:53,870 --> 00:05:54,710
That's what I've not done.
80
00:05:55,040 --> 00:05:57,230
Level current time start to zero.
81
00:05:57,560 --> 00:05:57,860
OK.
82
00:05:57,950 --> 00:06:06,230
So in the stop and say level, current time equals level time limits.
83
00:06:08,440 --> 00:06:08,840
There we go.
84
00:06:09,100 --> 00:06:12,100
So that will pass that throw through to that current time.
85
00:06:12,610 --> 00:06:18,340
Now, if you wanted, for example, to 60 or 90 or whatever you want, you can do so in the ed, and
86
00:06:18,340 --> 00:06:21,160
it will automatically pass it through to the level Covid time.
87
00:06:22,180 --> 00:06:25,660
So save that and then let's try it again.
88
00:06:26,140 --> 00:06:28,990
Well, we know it just pulls the game zero.
89
00:06:29,080 --> 00:06:29,650
So that's good.
90
00:06:34,920 --> 00:06:39,650
OK, instantly, there we go, and time is now going down each and every second.
91
00:06:40,820 --> 00:06:41,930
OK, excellent.
92
00:06:42,860 --> 00:06:51,950
And so what we'll do in the next video is we'll set it up so that when it reaches zero and it can actually
93
00:06:52,250 --> 00:06:53,720
load the next level.
8058
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.