1
00:00:03,070 --> 00:00:03,610
Hello again.

2
00:00:03,610 --> 00:00:05,350
In this lecture, we're doing something crazy.

3
00:00:05,350 --> 00:00:10,930
We're sterilizing our variables so that we can move our steer speed left and right within the inspector.

4
00:00:10,930 --> 00:00:15,340
So I can see how our game is going to look when we properly implement our steering.

5
00:00:15,340 --> 00:00:16,660
So let's get started.

6
00:00:16,660 --> 00:00:21,100
Making your variables available in the inspector will save you a lot of time and also help a lot if

7
00:00:21,100 --> 00:00:25,570
you're working with someone on your team who maybe is wearing the design hat and doesn't want to dig

8
00:00:25,570 --> 00:00:27,580
around in the code to see what's going on.

9
00:00:27,580 --> 00:00:30,520
So what we're going to do is use something called serialised field.

10
00:00:30,520 --> 00:00:36,040
So if you jump back into driver X and I find move speed, give myself a space before that, use the

11
00:00:36,040 --> 00:00:42,220
open square braces and you can see that Visual Studio code is automatically added the closed saying,

12
00:00:42,220 --> 00:00:47,350
I think you want to put something within here, I'm going to type in serialize field and you can see

13
00:00:47,350 --> 00:00:50,200
I just type in C, R and then it knows what the remainder is.

14
00:00:50,200 --> 00:00:55,360
You can click on that or hit tab or hit spacebar and that will complete serialize field and serialize

15
00:00:55,360 --> 00:00:57,310
field is an example of an attribute.

16
00:00:57,310 --> 00:01:02,710
This square braces, when we put it before a variable or a class or a method, shows that we're adding

17
00:01:02,710 --> 00:01:06,370
some sort of attribute to the thing that is following it.

18
00:01:06,370 --> 00:01:13,240
So Serialize Field is adding the attribute that allows us to serialize, in other words, right to disk

19
00:01:13,540 --> 00:01:14,740
this particular variable.

20
00:01:14,740 --> 00:01:17,230
And when we do that, we can access it in the inspector.

21
00:01:17,230 --> 00:01:22,180
So I'm going to save jump back into unity and you should see give it a moment to think about things.

22
00:01:22,180 --> 00:01:27,010
Make sure you clicked on your vehicle or your player you can see on the driver script.

23
00:01:27,010 --> 00:01:32,860
Now we have move speed and the number in here will be whatever we initialized this at, which is cool.

24
00:01:32,860 --> 00:01:40,450
Now I'm going to change the move speed to say 0.03 and then click on play and that should change my

25
00:01:40,450 --> 00:01:40,810
speed.

26
00:01:40,810 --> 00:01:47,530
So I'm moving quicker in this loop and then if I change it while I'm still in play mode to increase

27
00:01:47,530 --> 00:01:52,540
it while it goes way up, the screen goes really far so you can change it while it's in motion, which

28
00:01:52,540 --> 00:01:53,320
is pretty cool.

29
00:01:53,320 --> 00:01:55,090
I'm going to leave it at 0.03.

30
00:01:55,090 --> 00:01:59,650
Now, what I want to highlight here as well is as soon as you change this within the inspector, that

31
00:01:59,650 --> 00:02:00,820
will be the new value.

32
00:02:00,820 --> 00:02:05,560
Despite the fact when I go back here into my code, it's been initialized at 0.01.

33
00:02:05,560 --> 00:02:12,160
This is being overwritten by the value that I'm saving to my disk, which says 0.03.

34
00:02:12,160 --> 00:02:15,820
So sometimes that can get you a little bit of confusion where you're looking in your code and you're

35
00:02:15,820 --> 00:02:19,210
saying, hang on a minute, 0.01, why is it going so fast?

36
00:02:19,210 --> 00:02:24,820
As soon as you modify the value in the inspector, that becomes the overriding value and that's the

37
00:02:24,820 --> 00:02:25,960
one it's going to be using.

38
00:02:25,960 --> 00:02:27,580
Okay, so we've done that for move speed.

39
00:02:27,580 --> 00:02:29,260
Let's do that for steer speed.

40
00:02:29,260 --> 00:02:35,470
And this is time for a challenge for you serialize your steer speed using serialized field make steer

41
00:02:35,470 --> 00:02:37,450
speed available in the inspector.

42
00:02:37,450 --> 00:02:40,630
And then I've got another kind of quirky challenge for you here.

43
00:02:40,630 --> 00:02:43,060
Drive your car using the inspector.

44
00:02:43,060 --> 00:02:49,600
See if you can keep it on the screen for 10 seconds by modifying the value of the steer speed while

45
00:02:49,600 --> 00:02:50,830
you are playing the game.

46
00:02:50,830 --> 00:02:51,250
There you go.

47
00:02:51,250 --> 00:02:52,120
Take on that challenge.

48
00:02:52,120 --> 00:02:53,380
I'll see you back here when you're done.

49
00:02:56,010 --> 00:02:56,340
Okay.

50
00:02:56,340 --> 00:03:00,540
First step, we're going to put a serialized field in front of our steer speed.

51
00:03:00,540 --> 00:03:05,250
So serialize field hit tab to autocomplete complete click on save.

52
00:03:05,280 --> 00:03:08,730
Pretty straightforward to add that bit of code, jump back over into unity.

53
00:03:08,730 --> 00:03:13,860
It'll think for a second we should now have a second value, which is my steer speed.

54
00:03:13,860 --> 00:03:16,290
I'm going to pop my move speed down a little bit.

55
00:03:16,290 --> 00:03:17,250
I'm going to cheat a bit here.

56
00:03:17,250 --> 00:03:19,020
I'm going to move speed .01.

57
00:03:19,020 --> 00:03:20,600
So we're going a little bit slower now.

58
00:03:20,610 --> 00:03:21,210
Click on play.

59
00:03:21,210 --> 00:03:22,080
I'm going to get ready.

60
00:03:22,080 --> 00:03:26,790
Oversteer speed, it's doing some left so I'm going to turn it to increase it.

61
00:03:26,790 --> 00:03:30,600
Now I need to decrease it so it doesn't turn as much and then back the other way.

62
00:03:30,600 --> 00:03:31,620
That will turn it the other way.

63
00:03:31,620 --> 00:03:36,630
Okay, so we've got the fundamentals of steering our vehicle is a little bit clunky and not exactly

64
00:03:36,630 --> 00:03:40,650
how we'd want our player to play the game, but it is working and looks pretty cool.

65
00:03:40,650 --> 00:03:42,720
It's a car driving game and we can do this by.

66
00:03:42,720 --> 00:03:48,300
We're playing around with moving our steer speed in the inspector and obviously the next step is for

67
00:03:48,300 --> 00:03:53,280
us to hook this up so the player can use keys on their keyboard because obviously the player is not

68
00:03:53,280 --> 00:03:56,190
going to have access to the unity inspector when they're playing around.

69
00:03:56,190 --> 00:03:59,640
But this is the fundamental we've got move speed to go faster or slower.

70
00:03:59,640 --> 00:04:01,560
We've got steer speed to move left or right.

71
00:04:01,560 --> 00:04:02,400
So there we go.

72
00:04:02,400 --> 00:04:03,690
I'll see you in the next lecture.

