1
00:00:03,170 --> 00:00:08,330
In this video, we're going to fix a situation where the player could drive straight over to the customer

2
00:00:08,330 --> 00:00:11,270
and deliver the package, but they didn't actually ever pick up the package.

3
00:00:11,270 --> 00:00:16,020
So we want to make sure you can only deliver the package if you actually have the package.

4
00:00:16,040 --> 00:00:16,940
How do we do that?

5
00:00:16,970 --> 00:00:19,650
Well, we're going to do that using a bull.

6
00:00:19,670 --> 00:00:20,620
What is a bull?

7
00:00:20,630 --> 00:00:21,680
I hear you ask.

8
00:00:21,680 --> 00:00:27,800
Well, bulls are types of variables that can store one of two values, either true or false, and they're

9
00:00:27,800 --> 00:00:31,460
often used with if statements to decide whether something happens or not.

10
00:00:31,460 --> 00:00:33,530
So if something's true, do the thing.

11
00:00:33,530 --> 00:00:35,150
If it's false, don't do the thing.

12
00:00:35,150 --> 00:00:37,760
So bulls are very handy from that point of view.

13
00:00:37,760 --> 00:00:44,060
And in our code we're going to jump back over into our delivery script and write up the top up above

14
00:00:44,060 --> 00:00:45,650
our own collision.

15
00:00:45,650 --> 00:00:46,550
Enter right up here.

16
00:00:46,550 --> 00:00:52,130
We're going to create ourselves a variable which be of type bull and we'll call this has package.

17
00:00:52,130 --> 00:00:57,290
You want to make sure that you name your bulls in a way that it's clear that it's either true or false

18
00:00:57,290 --> 00:00:59,780
has packaged its true or has package is false.

19
00:00:59,780 --> 00:01:02,690
If you just name this for example package, what does that mean?

20
00:01:02,690 --> 00:01:03,320
Does it make sense?

21
00:01:03,320 --> 00:01:06,770
Does it mean it's a big package or small package or red package or blue package?

22
00:01:06,770 --> 00:01:10,490
But if we say has package, then that's do I have it or not?

23
00:01:10,490 --> 00:01:12,140
And we do semicolon here now.

24
00:01:12,140 --> 00:01:16,790
We didn't actually assign a value to it so we could assign it false to say we're pretty sure when the

25
00:01:16,790 --> 00:01:20,120
player starts the game it's going to be false or we could have signed it as true.

26
00:01:20,270 --> 00:01:21,770
When you start, you've got the package.

27
00:01:21,770 --> 00:01:22,130
It's true.

28
00:01:22,130 --> 00:01:23,690
But just a little experiment here.

29
00:01:23,690 --> 00:01:26,510
If we don't assign it anything, what will it be?

30
00:01:26,510 --> 00:01:27,230
How do we know?

31
00:01:27,230 --> 00:01:32,300
Well, we could go and Google the answer what the bulls default for in unity or we can do ourselves.

32
00:01:32,300 --> 00:01:33,830
Just a little quick experiment.

33
00:01:33,830 --> 00:01:39,950
We'll start and start or delete this again in a moment and start and we'll debug dot log and in our

34
00:01:39,950 --> 00:01:44,390
parentheses what is type has package and then semicolon.

35
00:01:44,390 --> 00:01:50,030
So what that would do when we first start our game, it'll just print out whether it has packages,

36
00:01:50,030 --> 00:01:50,660
true or false.

37
00:01:50,660 --> 00:01:52,940
So we'll save that back over into unity.

38
00:01:52,940 --> 00:01:54,950
We'll just do this as a little thought experiment.

39
00:01:54,950 --> 00:01:59,210
I also want to get you in the habit of doing printing things to the console so you know what's going

40
00:01:59,210 --> 00:01:59,360
on.

41
00:01:59,390 --> 00:02:04,190
You're constantly testing and looking and not getting sideswiped by these things, so it starts off

42
00:02:04,190 --> 00:02:05,690
as false.

43
00:02:05,690 --> 00:02:08,150
So we know for sure this starts off as false.

44
00:02:08,150 --> 00:02:13,820
That means that we won't be able to deliver the package until we actually go and get the package.

45
00:02:13,820 --> 00:02:15,050
So how do we get the package?

46
00:02:15,050 --> 00:02:20,690
Well, in our on trigger enter, we've got the if the other tag is package, then we want to pick it

47
00:02:20,690 --> 00:02:21,170
up.

48
00:02:21,170 --> 00:02:23,000
What would we do in this instance?

49
00:02:23,000 --> 00:02:30,140
After we pick it up, we want to change our ball to be something we want to change it to be has package

50
00:02:30,140 --> 00:02:33,140
equals what equals true.

51
00:02:33,140 --> 00:02:38,150
So the logic here is if we bump into something that is the package now that has package ball or that

52
00:02:38,150 --> 00:02:40,040
has package variable, we'll be true.

53
00:02:40,040 --> 00:02:40,550
Excellent.

54
00:02:40,550 --> 00:02:45,560
When we bump into the customer, we need a way of saying okay, the other tag has to be the customer

55
00:02:45,560 --> 00:02:50,870
and you actually need to have the package, my friend, or else I'm not going to accept delivery.

56
00:02:50,890 --> 00:02:53,150
The way we can do that is in our if statement.

57
00:02:53,150 --> 00:02:54,770
We can have multiple things.

58
00:02:54,770 --> 00:02:56,900
We're checking to see whether they're true or not.

59
00:02:56,900 --> 00:02:58,730
So it can be saying, is it the customer?

60
00:02:58,730 --> 00:03:00,980
And then we can use the double ampersand.

61
00:03:00,980 --> 00:03:04,400
That's what that little symbol is called, ampersand or it's called the end sign.

62
00:03:04,400 --> 00:03:10,880
So you do two and back to back that's the and operator and then we're going to type in simply has package

63
00:03:10,880 --> 00:03:15,950
we don't need to say has package equals true you could do that but you don't need to because when you

64
00:03:15,950 --> 00:03:20,000
just add in the variable in here, it's going to say, okay, it's a ball.

65
00:03:20,000 --> 00:03:21,560
If it's true, do the thing.

66
00:03:21,560 --> 00:03:23,000
If it's false, don't do the thing.

67
00:03:23,000 --> 00:03:26,000
So let's save that and see if that actually works.

68
00:03:26,000 --> 00:03:30,830
We'll do, first of all, by driving over our customer and see what message we get.

69
00:03:30,830 --> 00:03:33,140
Make sure we don't accidentally pick up the package.

70
00:03:33,140 --> 00:03:34,400
Drive, drive, drive, drive.

71
00:03:34,400 --> 00:03:35,240
What happens here?

72
00:03:35,240 --> 00:03:35,690
Nothing.

73
00:03:35,690 --> 00:03:36,590
Nothing gets printed.

74
00:03:36,590 --> 00:03:39,410
The customer is like, well, unless we bump into the house and it says, ouch.

75
00:03:39,440 --> 00:03:42,530
Customer is like, No, man, I don't know what you're talking about.

76
00:03:42,530 --> 00:03:47,570
We go over, we get the package now we've got the package picked up, drive back over to the customer

77
00:03:47,570 --> 00:03:49,340
and yes, package delivered.

78
00:03:49,340 --> 00:03:50,570
Excellent.

79
00:03:50,600 --> 00:03:52,430
However, what's going on here?

80
00:03:52,430 --> 00:03:53,810
Oh, I can keep delivering the package.

81
00:03:53,810 --> 00:03:59,060
I'll deliver it another time and get, you know, suite, bonus and commission and another commission.

82
00:03:59,060 --> 00:03:59,420
Okay.

83
00:03:59,420 --> 00:04:02,060
So we need to do something so that we can't keep doing that.

84
00:04:02,060 --> 00:04:05,630
We can't exploit that because, you know, your players absolutely exploit that.

85
00:04:05,630 --> 00:04:07,220
So little challenge for you here.

86
00:04:07,220 --> 00:04:13,070
I don't have a slide, but the challenge is add some logic to make sure that we can't deliver the package

87
00:04:13,070 --> 00:04:13,970
over and over.

88
00:04:13,970 --> 00:04:15,110
So what do you think we would do?

89
00:04:15,140 --> 00:04:16,670
Pause the video and have a go at that?

90
00:04:18,760 --> 00:04:24,580
So in logic we need to say once we've delivered the package, then we don't have the package anymore.

91
00:04:24,580 --> 00:04:30,760
So has package is going to equal false and let's just check that that works.

92
00:04:30,760 --> 00:04:33,790
Before we celebrate too much, click on play.

93
00:04:33,820 --> 00:04:35,560
We'll go through this standard process.

94
00:04:35,560 --> 00:04:37,900
We'll make sure that we can't deliver it until we have it.

95
00:04:37,900 --> 00:04:38,680
No, we can't.

96
00:04:38,680 --> 00:04:42,040
We'll grab it and then we'll bump into a tree, then we'll deliver it.

97
00:04:42,040 --> 00:04:42,250
Yes.

98
00:04:42,250 --> 00:04:43,090
Package delivered.

99
00:04:43,090 --> 00:04:44,170
And then is it going up?

100
00:04:44,170 --> 00:04:45,310
No, the number doesn't go up.

101
00:04:45,310 --> 00:04:48,880
But if we go back over, we grab the package again and then drive back over.

102
00:04:48,880 --> 00:04:51,190
It does go up exactly as we want it to do.

103
00:04:51,190 --> 00:04:51,850
So there we go.

104
00:04:51,850 --> 00:04:56,230
We've used a ball in conjunction with our if statement to make sure that we can only deliver the package

105
00:04:56,230 --> 00:04:57,550
if we have the package.

106
00:04:57,640 --> 00:04:59,140
Okay, I'll see you in the next lecture.

