1
00:00:03,160 --> 00:00:05,830
In this lecture, we're setting it up so you can pick up the package.

2
00:00:05,830 --> 00:00:06,670
It disappears.

3
00:00:06,670 --> 00:00:09,970
You can't pick up another package until you deliver that package.

4
00:00:09,970 --> 00:00:13,500
Then after you deliver that, you can go pick up the next package and so on.

5
00:00:13,510 --> 00:00:14,830
So let's get started.

6
00:00:15,040 --> 00:00:18,940
First step we need to create a couple of extra packages to deliver and scatter them around our map.

7
00:00:18,940 --> 00:00:24,220
So I'm going to click on a package control DX to duplicate and then move that to a different spot over

8
00:00:24,220 --> 00:00:28,150
here and then control DX one more time and pop that over here as well.

9
00:00:28,150 --> 00:00:31,120
Not trying to hide them too much yet we're still in the prototyping phase.

10
00:00:31,120 --> 00:00:34,510
Side note, I think this circle, we don't need that anymore, so I'm going to delete that.

11
00:00:34,510 --> 00:00:38,740
So I have three packages floating around in our scene for us to to drive over.

12
00:00:38,740 --> 00:00:43,060
And if I click on one of these objects, if I want to hide this, I've got a few options.

13
00:00:43,060 --> 00:00:47,620
First of all, I could just disable the entire object so it just goes away.

14
00:00:47,620 --> 00:00:48,850
And that's one thing we can do.

15
00:00:48,850 --> 00:00:49,930
That's totally fine.

16
00:00:49,930 --> 00:00:54,100
I can also just turn off the Sprite renderer, but then I'd probably also have to turn off the box.

17
00:00:54,100 --> 00:00:56,560
Collider So these are things that we can do as well.

18
00:00:56,560 --> 00:01:01,300
We can access these components and say, do the equivalent of what I'm doing here, which is turning

19
00:01:01,300 --> 00:01:02,860
the checkbox on and off.

20
00:01:02,860 --> 00:01:06,700
However, for me, I don't want to use this package ever again.

21
00:01:06,700 --> 00:01:11,740
Once I drive over it, I consider that it's been picked up and it's never going to appear in the game

22
00:01:11,740 --> 00:01:12,340
ever again.

23
00:01:12,340 --> 00:01:17,620
I want to do the equivalent of hitting delete and getting rid of that entire thing so it's no longer

24
00:01:17,620 --> 00:01:18,220
sitting just there.

25
00:01:18,220 --> 00:01:19,510
I'm going to undo that delete.

26
00:01:19,510 --> 00:01:24,040
And to do that we can use destroy and I want to show you destroy because destroy is a handy thing to

27
00:01:24,040 --> 00:01:28,570
know how to actually delete something from your scene and to destroy game objects.

28
00:01:28,570 --> 00:01:29,920
We call destroy.

29
00:01:29,920 --> 00:01:30,790
So we call destroy.

30
00:01:30,790 --> 00:01:34,360
Specifically delete a game object from our scene.

31
00:01:34,360 --> 00:01:37,750
Destroy when we call, it requires us to tell it.

32
00:01:37,750 --> 00:01:43,390
In other words, pass in two things and we pass those things in to these parentheses.

33
00:01:43,390 --> 00:01:44,500
So we have to tell it something.

34
00:01:44,500 --> 00:01:45,430
What do we need to tell it?

35
00:01:45,430 --> 00:01:51,640
We need to tell it which game object to destroy and how much time to wait until it is destroyed.

36
00:01:51,640 --> 00:01:54,490
Now it's actually optional to pass in the delay.

37
00:01:54,490 --> 00:01:57,820
If you don't have anything in there, then it will just destroy immediately.

38
00:01:57,820 --> 00:02:02,770
But for the purpose of this challenge, I'd like for you to put in both the game object and the amount

39
00:02:02,770 --> 00:02:05,920
of time you would like to pause until it is destroyed.

40
00:02:05,920 --> 00:02:10,570
And so in our case, where we're looking to destroy something other than us, we would need to type,

41
00:02:10,570 --> 00:02:16,570
destroy, and then in parentheses the monster or whatever the particular thing is that we want to destroy

42
00:02:16,600 --> 00:02:18,040
dot game object.

43
00:02:18,050 --> 00:02:22,330
So we need to say it's the game object we're interested in comma and then the delay.

44
00:02:22,330 --> 00:02:28,210
So in this case I'm saying 0.05 F Now before I give you a challenge, I'll give you one or two other

45
00:02:28,210 --> 00:02:28,990
clues in here.

46
00:02:28,990 --> 00:02:32,530
So we need to destroy the package after we pick it up.

47
00:02:32,530 --> 00:02:35,080
So we'll need to destroy it in a particular place.

48
00:02:35,080 --> 00:02:37,210
And also, what are we destroying?

49
00:02:37,210 --> 00:02:42,130
Well, the clue I'll give you is that this other is the game object.

50
00:02:42,130 --> 00:02:45,280
So when we're getting the information, it's telling us the other thing.

51
00:02:45,280 --> 00:02:46,930
It's starting off saying, here's the game object.

52
00:02:46,930 --> 00:02:48,220
In other words, we'll call it other.

53
00:02:48,220 --> 00:02:50,980
We'll name the game object that you bumped into other.

54
00:02:50,980 --> 00:02:52,840
So there's a couple of hints for you.

55
00:02:52,870 --> 00:02:53,770
Here's the challenge.

56
00:02:53,770 --> 00:02:57,370
So destroy each package that you run over after 1/2.

57
00:02:57,370 --> 00:02:58,960
Only destroy the one that you run over.

58
00:02:58,960 --> 00:02:59,950
Don't destroy all of them.

59
00:02:59,950 --> 00:03:06,040
But after you run over it, use destroy to remove that package so that we can pick them up and not have

60
00:03:06,040 --> 00:03:06,970
them in the game anymore.

61
00:03:06,970 --> 00:03:12,040
And I'd also like you to set up a variable and use serialized fields so that we can tune in the inspector

62
00:03:12,040 --> 00:03:14,770
how long the delay is before the package disappears.

63
00:03:14,770 --> 00:03:16,870
We don't need to go and find it in the code.

64
00:03:16,870 --> 00:03:21,160
We can do that from in the inspector and say half a second or 2 seconds we can shoot it from there.

65
00:03:21,160 --> 00:03:22,000
So there you go.

66
00:03:22,000 --> 00:03:22,690
There's your challenge.

67
00:03:22,690 --> 00:03:25,060
Take that on and I'll see you back here when you're done.

68
00:03:27,490 --> 00:03:27,840
Okay.

69
00:03:27,850 --> 00:03:29,680
So where do we need to destroy?

70
00:03:29,710 --> 00:03:30,890
We need to destroy.

71
00:03:30,910 --> 00:03:34,270
After we've gone and picked up the package, then we say, get rid of that package.

72
00:03:34,270 --> 00:03:35,860
So I'm going to give myself a new line.

73
00:03:35,950 --> 00:03:37,660
Destroy in parentheses.

74
00:03:37,660 --> 00:03:41,290
I need to access other because that's the other thing we're interested in.

75
00:03:41,290 --> 00:03:43,900
But I need to access the game object.

76
00:03:43,900 --> 00:03:47,020
You see, the very first property we can get at here is game object.

77
00:03:47,020 --> 00:03:51,670
So game object, that's the thing I'm destroying because Destroy wants to know the game object and then

78
00:03:51,670 --> 00:03:56,560
comma, I can type in 0.5 F and then semicolon.

79
00:03:56,560 --> 00:04:01,690
However, I challenge you not to have this magic number to serialize a variable, so I'm going to jump

80
00:04:01,690 --> 00:04:08,740
up at the top of my class just above bool serialize field and then it will be of type what it's type

81
00:04:08,740 --> 00:04:09,160
float.

82
00:04:09,160 --> 00:04:10,660
We know that because there's an F down the end.

83
00:04:10,660 --> 00:04:14,770
But if we mouse over here it's looking for destroys looking for a float.

84
00:04:14,800 --> 00:04:20,529
T you can see just in here gives you a hint object and then float.

85
00:04:20,529 --> 00:04:29,140
So we'll add a float and we'll call this destroy delay and I'm going to initialize that at 0.5 F, so

86
00:04:29,140 --> 00:04:31,090
I'm going to give it a starting value.

87
00:04:31,090 --> 00:04:37,300
It'll be at 0.5 F, then down here instead of 0.5 F, I will call this destroy delay.

88
00:04:38,020 --> 00:04:40,780
Now let's save that back over into unity.

89
00:04:40,780 --> 00:04:43,000
We'll make sure everything's hooked up the way we expect it to.

90
00:04:43,000 --> 00:04:46,150
If we click on Cruisy MC Drive, we'll see.

91
00:04:46,150 --> 00:04:46,930
Let's see.

92
00:04:46,930 --> 00:04:47,350
Where is it?

93
00:04:47,350 --> 00:04:51,250
Down the bottom here we have a destroyed delay currently on 0.5.

94
00:04:51,280 --> 00:04:54,670
If I click on play, drive over.

95
00:04:55,420 --> 00:04:56,290
Bup bup bup.

96
00:04:56,980 --> 00:04:57,520
Yes.

97
00:04:57,520 --> 00:05:00,400
After we touched it, there was a little bit of a delay, then it disappeared.

98
00:05:00,400 --> 00:05:01,930
What happens with this one?

99
00:05:02,410 --> 00:05:03,640
Yeah, it delays as well.

100
00:05:03,640 --> 00:05:05,350
So they're all set up with that delay.

101
00:05:05,350 --> 00:05:06,100
This is a good thing.

102
00:05:06,100 --> 00:05:11,860
Just for me to note briefly, is that once you change something on a script, it applies to all the

103
00:05:11,860 --> 00:05:14,080
places that script is being referenced.

104
00:05:14,080 --> 00:05:19,210
So over here the delivery script is places a component and then it's looking at the information within

105
00:05:19,210 --> 00:05:19,540
the script.

106
00:05:19,540 --> 00:05:23,320
So you don't need to go and say, change the details of script, their details, the script, their

107
00:05:23,320 --> 00:05:25,240
details, the script, they're the script.

108
00:05:25,240 --> 00:05:30,250
If you're pointing to it from this game object, it will update in all those places just in case.

109
00:05:30,250 --> 00:05:32,530
In case that hasn't been clear, I wanted to point that out.

110
00:05:32,530 --> 00:05:34,030
Now you can see another problem.

111
00:05:34,030 --> 00:05:36,970
The player can go and pick up a whole bunch of packages.

112
00:05:36,970 --> 00:05:37,690
That might be fine.

113
00:05:37,690 --> 00:05:41,020
You might want to let the player pick up all the packages, but for me, I don't want to do that.

114
00:05:41,020 --> 00:05:45,250
So let's have a look at our logic here and say, how can we make it that the player can only pick up

115
00:05:45,250 --> 00:05:46,870
one package at a time?

116
00:05:46,870 --> 00:05:51,340
Well, what could we do up here saying if the other tag is package?

117
00:05:51,340 --> 00:05:54,760
So if we drive a a package and something is the case.

118
00:05:54,760 --> 00:05:56,800
Well, and what do we want to say in here?

119
00:05:56,800 --> 00:06:00,010
We want to say, well, if you don't currently have a package.

120
00:06:00,010 --> 00:06:01,270
And how do we write that?

121
00:06:01,270 --> 00:06:05,320
Well, we could say has package equals equals false.

122
00:06:05,320 --> 00:06:06,730
That would be one way of writing it.

123
00:06:06,730 --> 00:06:11,740
However, there's a shorthand way we can write this is by saying in front of a house package, add an

124
00:06:11,740 --> 00:06:15,610
exclamation mark, which is a way of saying not exclamation mark is not.

125
00:06:15,610 --> 00:06:25,840
So we're saying here, if other tag is package is true and not has package is true, then do these things

126
00:06:25,840 --> 00:06:30,880
which like I said before, is another way of saying has package equals equals false.

127
00:06:30,880 --> 00:06:34,930
So let's check that that works back over into our game.

128
00:06:34,930 --> 00:06:39,550
We want to pick out one package and then make sure we can't pick up any other packages now that we're

129
00:06:39,550 --> 00:06:41,680
using our not operator.

130
00:06:42,740 --> 00:06:44,130
Pick that one up yet?

131
00:06:44,160 --> 00:06:45,140
Bit of a delay.

132
00:06:45,170 --> 00:06:46,160
Try to pick this one up.

133
00:06:46,160 --> 00:06:49,440
I won't let us pick it up because we already have a package.

134
00:06:49,460 --> 00:06:49,880
Excellent.

135
00:06:49,880 --> 00:06:51,410
So that's exactly what I wanted to do.

136
00:06:51,440 --> 00:06:52,350
We can deliver there.

137
00:06:52,370 --> 00:06:53,360
Pick up the next one.

138
00:06:53,360 --> 00:06:55,640
Deliver their delivered backwards driving.

139
00:06:55,640 --> 00:06:58,910
Pick up that one and deliver all of them exactly as we wanted to do.

140
00:06:58,940 --> 00:06:59,890
Great stuff.

141
00:06:59,900 --> 00:07:00,160
Okay.

142
00:07:00,200 --> 00:07:01,070
That's all for this lecture.

143
00:07:01,070 --> 00:07:02,000
I will see you in the next one.

