1
00:00:03,050 --> 00:00:06,770
In this lecture, we're adding some coins that spin around, have a bit of animation, and when we drop

2
00:00:06,770 --> 00:00:08,390
onto them, we can pick them up.

3
00:00:08,390 --> 00:00:10,270
So let's work on our pickups.

4
00:00:10,280 --> 00:00:14,600
I'll be working in level two for this exercise and something I just noticed a little bit messy.

5
00:00:14,600 --> 00:00:17,990
We've got all these enemies hanging around, so I'm going to right click Create Empty.

6
00:00:17,990 --> 00:00:24,080
I'll call this enemies as just an empty game object, reset the transform and then grab all the goobers

7
00:00:24,080 --> 00:00:26,990
and shove them under the enemies game object.

8
00:00:26,990 --> 00:00:28,010
That should be okay.

9
00:00:28,010 --> 00:00:29,450
I can't see any issues there.

10
00:00:29,450 --> 00:00:30,560
Famous last words.

11
00:00:30,590 --> 00:00:35,000
Now if you jump into your sprites folder, there should be the coins that we downloaded.

12
00:00:35,000 --> 00:00:36,590
When we downloaded all the sprites.

13
00:00:36,590 --> 00:00:40,130
And you can see if we click on the Sprite editor, they've all been chopped up already.

14
00:00:40,130 --> 00:00:40,640
That's good.

15
00:00:40,640 --> 00:00:43,460
They look like they're chopped up in the right kind of way.

16
00:00:43,460 --> 00:00:48,380
So now we're right click create an empty I'm going to call this pick ups just because there might be

17
00:00:48,380 --> 00:00:50,930
a bunch of different pick ups, right click reset transform.

18
00:00:50,930 --> 00:00:53,270
Then underneath here, right click, create empty.

19
00:00:53,270 --> 00:00:54,650
I will call this coin.

20
00:00:54,650 --> 00:00:57,290
Now for coin we need to add a bunch of components.

21
00:00:57,290 --> 00:01:02,060
Let's do this nice and fast will add a sprite renderer and we pick one of our sprites.

22
00:01:02,060 --> 00:01:03,320
So we'll go and pick one of the coins.

23
00:01:03,320 --> 00:01:04,340
That one there looks pretty good.

24
00:01:04,340 --> 00:01:05,600
What if it was coin zero?

25
00:01:05,600 --> 00:01:07,190
So we've got some visualization.

26
00:01:07,190 --> 00:01:09,920
We can't see it because it's all the way underneath something.

27
00:01:09,920 --> 00:01:13,030
So let's have a look at our sorting layers from default.

28
00:01:13,070 --> 00:01:16,910
We'll put on interactive tiles because that's what this is similar to our portal.

29
00:01:16,910 --> 00:01:17,990
It's an interactive will.

30
00:01:17,990 --> 00:01:21,300
We also need to change the layer to be an interactive.

31
00:01:21,300 --> 00:01:24,290
Well, that's great, except we need to add a collider.

32
00:01:24,290 --> 00:01:25,520
I'll add a let's say.

33
00:01:25,520 --> 00:01:27,680
Collider What should we add a circle?

34
00:01:27,680 --> 00:01:30,110
Collider I think because it's kind of circle in shape.

35
00:01:30,410 --> 00:01:31,310
Scroll right in.

36
00:01:31,310 --> 00:01:33,500
I'm going to click on my edit shape.

37
00:01:33,500 --> 00:01:37,310
Just make it the appropriate size wrapped around there.

38
00:01:37,340 --> 00:01:42,110
We'll make this a trigger so that we can tap it and trigger it, and that should be pretty good for

39
00:01:42,140 --> 00:01:42,710
that next step.

40
00:01:42,710 --> 00:01:44,720
What we want to do is deal with the animation.

41
00:01:44,720 --> 00:01:46,760
So we've got our spinny spinny thing here.

42
00:01:46,760 --> 00:01:50,570
Add a component, animator and animator component.

43
00:01:50,570 --> 00:01:53,000
When we do these things now let's find our sprites.

44
00:01:53,000 --> 00:01:54,650
I'm going to select all of them.

45
00:01:54,650 --> 00:01:56,900
Select, select, select, group, select.

46
00:01:56,900 --> 00:01:57,590
Did I get them all?

47
00:01:57,590 --> 00:01:58,460
Yes, I think I did.

48
00:01:58,460 --> 00:02:06,530
Right click create animation and we'll call this coin spin animation will drag coin spin animation into

49
00:02:06,530 --> 00:02:07,730
the animations folder.

50
00:02:07,730 --> 00:02:09,710
We also need an animator controller.

51
00:02:09,710 --> 00:02:14,720
So I'm going to right click in here, create a animator controller.

52
00:02:14,720 --> 00:02:20,210
The animator controller will call, let's see, coin coins coin, probably coin because we're spinning

53
00:02:20,210 --> 00:02:22,100
one at a time aren't we, coin.

54
00:02:22,100 --> 00:02:27,080
And if I click on this coin animated controller, open up our animator, you can see there's not much

55
00:02:27,080 --> 00:02:28,340
going on here at the moment.

56
00:02:28,340 --> 00:02:32,270
Scrolling a little bit, I'm going to drag my coin spin just into the middle.

57
00:02:32,270 --> 00:02:36,470
So we'll go straight from entry to coin spin.

58
00:02:36,470 --> 00:02:36,920
That's cool.

59
00:02:36,920 --> 00:02:38,270
We don't need to worry about transitions.

60
00:02:38,270 --> 00:02:40,100
It's going to go straight into there to hang around.

61
00:02:40,100 --> 00:02:41,300
Click on Coin Spin.

62
00:02:41,300 --> 00:02:44,780
Just make sure we don't forget loop time because we want it to keep going and going.

63
00:02:44,780 --> 00:02:46,730
That should be the foundations of it.

64
00:02:46,730 --> 00:02:53,930
The last thing we need to do is click on the coin itself and to set up what we need to connect the animator

65
00:02:53,930 --> 00:02:55,070
to the animated controller.

66
00:02:55,070 --> 00:02:59,840
So we look for the controller, click our selector and select on coin.

67
00:02:59,990 --> 00:03:02,810
Let's click on play and see if it's actually doing what it's supposed to do with it.

68
00:03:02,810 --> 00:03:03,500
Spinning.

69
00:03:03,500 --> 00:03:04,160
Yes, it is.

70
00:03:04,160 --> 00:03:04,970
Mission accomplished.

71
00:03:04,970 --> 00:03:08,090
We can't pick it up yet though, so let's work on that next.

72
00:03:08,090 --> 00:03:13,190
So I'm going to jump into scripts, make ourselves a new script, right click, create C-sharp script.

73
00:03:13,190 --> 00:03:20,240
I'll call this coin pickup pickup because other pickups might behave differently to our coin pick up.

74
00:03:20,240 --> 00:03:21,410
So we'll call it coin pick up.

75
00:03:21,410 --> 00:03:25,400
But in the future, maybe we just have all pick ups that give you points and stuff and we just need

76
00:03:25,400 --> 00:03:26,390
the one pick up script.

77
00:03:26,390 --> 00:03:30,710
But for now, I'll call it coin pick up just because I'm not exactly sure what we're doing down the

78
00:03:30,710 --> 00:03:31,070
track.

79
00:03:31,160 --> 00:03:32,450
Going to get rid of start and update.

80
00:03:32,450 --> 00:03:37,220
I don't think I'm going to need those, but what I do need is to give you a challenge, and that is

81
00:03:37,220 --> 00:03:38,480
to pick up the coin.

82
00:03:38,480 --> 00:03:44,210
When the player touches the coin, destroy the coin so that it disappears and make sure that it's only

83
00:03:44,210 --> 00:03:46,220
the player who can pick that coin up.

84
00:03:46,220 --> 00:03:46,880
There's a challenge.

85
00:03:46,880 --> 00:03:47,450
Pause video.

86
00:03:47,450 --> 00:03:48,740
See you back here when you've done.

87
00:03:51,280 --> 00:03:52,180
Okay.

88
00:03:52,180 --> 00:03:53,530
So let's have a look at what we need to do.

89
00:03:53,530 --> 00:03:56,050
Well, we need to do something to do with a trigger.

90
00:03:56,050 --> 00:04:00,340
So on trigger enter to DH looks pretty good.

91
00:04:00,370 --> 00:04:02,920
Get rid of the private and tidy up.

92
00:04:03,900 --> 00:04:06,530
Now parentheses out Kelly braces.

93
00:04:06,740 --> 00:04:08,390
Now, if what?

94
00:04:08,390 --> 00:04:09,740
We just did this last lecture, didn't we?

95
00:04:09,740 --> 00:04:14,180
If other dot tag equals equals player.

96
00:04:14,180 --> 00:04:17,690
That's right, player, then we need to do something pretty simple.

97
00:04:17,690 --> 00:04:21,320
We need to just destroy the game object.

98
00:04:21,320 --> 00:04:22,460
So destroy me.

99
00:04:22,460 --> 00:04:24,620
The thing that I'm on, which is the coin.

100
00:04:24,620 --> 00:04:29,450
So we'll save that back over into unity and you know, we'll put a couple of other coins in there just

101
00:04:29,450 --> 00:04:31,520
to make sure it's not a fluke that we did one.

102
00:04:31,520 --> 00:04:35,810
And by doing that, it's reminded me we need to prefab our coins.

103
00:04:35,810 --> 00:04:36,920
So this is great.

104
00:04:37,400 --> 00:04:41,720
I'm just going to change my size in here by holding down control and mouse wheel or just grabbing that

105
00:04:41,720 --> 00:04:49,070
selector and drag coin down into the prefab folder and then drag a couple more of those into the world.

106
00:04:49,490 --> 00:04:50,660
Click on play.

107
00:04:51,050 --> 00:04:54,500
Let's see if we've forgotten some sort of collision related thing or if we're good here.

108
00:04:54,500 --> 00:04:55,700
So full.

109
00:04:55,700 --> 00:04:56,250
Yes.

110
00:04:56,270 --> 00:04:57,830
No, we're not picking it up.

111
00:04:57,830 --> 00:04:58,730
So let's have a look at there.

112
00:04:58,730 --> 00:05:00,410
It might be a layer issue.

113
00:05:00,440 --> 00:05:04,550
Let's have a look at our edit and project settings and.

114
00:05:05,070 --> 00:05:06,590
It's colliding with everything at the moment.

115
00:05:06,590 --> 00:05:07,820
I don't think that's a good thing.

116
00:05:07,820 --> 00:05:10,040
So interactive is just with the player.

117
00:05:10,130 --> 00:05:11,240
I think that'll fix it.

118
00:05:11,240 --> 00:05:12,250
But no, you never know.

119
00:05:12,260 --> 00:05:12,920
We'll see.

120
00:05:12,920 --> 00:05:17,510
And X out of that click on play now we'll see if we can drop down.

121
00:05:17,510 --> 00:05:24,680
The player is colliding we have is trigger we are a player point oh I think I've just figured it out.

122
00:05:24,680 --> 00:05:25,370
Bonus points.

123
00:05:25,370 --> 00:05:29,180
If you can figure out what I've done wrong, just yell it at the screen really loud so your neighbors

124
00:05:29,180 --> 00:05:29,750
hear it.

125
00:05:29,750 --> 00:05:31,520
Rick has forgotten to do what?

126
00:05:31,790 --> 00:05:34,910
He's forgotten to put the script on the game object.

127
00:05:34,910 --> 00:05:35,690
Nice work, Rick.

128
00:05:35,690 --> 00:05:43,700
Add component coin, pick up script, and then we will scroll all the way up to the top and apply all.

129
00:05:43,700 --> 00:05:45,080
So that will go back to the prefab.

130
00:05:45,080 --> 00:05:49,820
And you know, the other thing that I didn't do that I just realized then is this is the reason that

131
00:05:49,820 --> 00:05:55,160
we work in the prefab is that I just noticed I haven't tagged my player as player, so that's a little

132
00:05:55,160 --> 00:05:56,300
bit sloppy on my part.

133
00:05:56,330 --> 00:05:58,520
Now I'm going to override a play also.

134
00:05:58,520 --> 00:06:02,690
Now if I click on my player prefab, that should all be tagged as player.

135
00:06:02,690 --> 00:06:04,160
So that's why we work in the prefab.

136
00:06:04,190 --> 00:06:06,710
That's why we apply back to the prefab regularly.

137
00:06:06,710 --> 00:06:10,220
That's why we all look a little bit foolish when we don't do these things.

138
00:06:10,220 --> 00:06:12,260
Hopefully now everything is working.

139
00:06:12,260 --> 00:06:17,960
If we drop down onto the coin, it knows that we're the player and it knows that it disappears.

140
00:06:17,960 --> 00:06:18,320
Excellent.

141
00:06:18,410 --> 00:06:18,770
There we go.

142
00:06:18,770 --> 00:06:19,840
With a little bit of messing around.

143
00:06:19,850 --> 00:06:21,230
We've got our coin to work.

144
00:06:21,230 --> 00:06:25,550
The moral of the story is make sure you apply everything back to your prefab or work directly into your

145
00:06:25,550 --> 00:06:26,150
prefab.

146
00:06:26,150 --> 00:06:30,950
There's more setting up to do in the next lecture to get our coins behaving with more functionality.

147
00:06:30,950 --> 00:06:32,480
So I will see you shortly.

