1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:02,000
In this video, we're going to make a coin for our game.

3
00:00:02,000 --> 00:00:04,000
It's going to be very simple task, honestly.

4
00:00:04,000 --> 00:00:07,000
And we're going to begin with adding graphics to the coin.

5
00:00:07,000 --> 00:00:10,000
We already have an object in the game, this one, but it's empty.

6
00:00:10,000 --> 00:00:13,000
So what we can do is to add Sprite Renderer.

7
00:00:15,000 --> 00:00:16,000
Sprite renderer.

8
00:00:17,000 --> 00:00:18,000
Oh, wait a second.

9
00:00:18,000 --> 00:00:19,000
Mouse highlight.

10
00:00:21,000 --> 00:00:23,000
So we have Sprite Renderer.

11
00:00:23,000 --> 00:00:26,000
Now we can go to graphics, find coin.

12
00:00:26,000 --> 00:00:29,000
Make sure we have pixels per unit 16.

13
00:00:29,000 --> 00:00:32,000
All right, now let's select coin and drag Sprite over here.

14
00:00:32,000 --> 00:00:36,000
Now we need to change certain layer and we can choose collectible.

15
00:00:37,000 --> 00:00:38,000
All right.

16
00:00:38,000 --> 00:00:40,000
Now, let's close this.

17
00:00:40,000 --> 00:00:43,000
We can go to assets animations.

18
00:00:43,000 --> 00:00:47,000
I'm going to create a folder for player animations layer.

19
00:00:51,000 --> 00:00:56,000
Then I'm going to drag all of this inside and I can create new animator controller.

20
00:00:56,000 --> 00:00:59,000
Over here going a C.

21
00:01:00,000 --> 00:01:02,000
Let's drag it to the coin like that.

22
00:01:02,000 --> 00:01:09,000
Then we can go to animation window and create new clip that's going to be just coin idle.

23
00:01:10,000 --> 00:01:14,000
We're not going to have any other animations for COIN, but it's kind of a good practice to give an

24
00:01:14,000 --> 00:01:15,000
understandable name.

25
00:01:15,000 --> 00:01:20,000
Let's go to graphics now and just take all of the sprites of the coin and drag it inside to coin idle.

26
00:01:20,000 --> 00:01:24,000
And I want to change sample rate to something like six.

27
00:01:25,000 --> 00:01:25,000
Let's see.

28
00:01:27,000 --> 00:01:28,000
Can this.

29
00:01:29,000 --> 00:01:34,000
I also think we could make this coin a bit smaller because it's kind of bigger than even the head of

30
00:01:34,000 --> 00:01:35,000
the player.

31
00:01:35,000 --> 00:01:37,000
So we can do maybe.

32
00:01:38,000 --> 00:01:39,000
Point eight.

33
00:01:41,000 --> 00:01:41,000
Let's see.

34
00:01:43,000 --> 00:01:44,000
I think it's okay.

35
00:01:44,000 --> 00:01:46,000
If not, we can change it later.

36
00:01:46,000 --> 00:01:48,000
So now we have a coin.

37
00:01:49,000 --> 00:01:53,000
Now let's go to a script of the coin, and I'm going to explain how it's going to work.

38
00:01:54,000 --> 00:01:55,000
So we can delete this.

39
00:01:55,000 --> 00:01:59,000
And we need one function that you've seen already in this project.

40
00:01:59,000 --> 00:02:03,000
And if you have some experience with unity, you've probably seen this function before and you used

41
00:02:03,000 --> 00:02:09,000
it on trigger enter two D, So on trigger enter is called whenever something enters the trigger.

42
00:02:09,000 --> 00:02:11,000
Now how do you create the trigger?

43
00:02:11,000 --> 00:02:12,000
Also, very simple.

44
00:02:12,000 --> 00:02:15,000
Let's go back to Unity and add Collider.

45
00:02:15,000 --> 00:02:17,000
I'm going to choose Box Collider.

46
00:02:18,000 --> 00:02:23,000
I know it's a coin and we could use Circle Collider, but I think it's nothing bad if you make Collider

47
00:02:23,000 --> 00:02:27,000
a bit bigger than the coin is, so it's easier to pick up for the player.

48
00:02:27,000 --> 00:02:30,000
So we kind of help the player without even him knowing it.

49
00:02:31,000 --> 00:02:33,000
So let's adjust the size.

50
00:02:33,000 --> 00:02:35,000
Just approximately bigger.

51
00:02:35,000 --> 00:02:36,000
Nothing special.

52
00:02:36,000 --> 00:02:37,000
And then we can check.

53
00:02:37,000 --> 00:02:40,000
This box is trigger, which is important.

54
00:02:41,000 --> 00:02:41,000
Click.

55
00:02:42,000 --> 00:02:43,000
Now it is a trigger.

56
00:02:43,000 --> 00:02:48,000
And now whenever something enters the trigger, we can do something again.

57
00:02:48,000 --> 00:02:54,000
But I want to do something specific because at the moment, anything that will enter the trigger will

58
00:02:54,000 --> 00:02:55,000
trigger it.

59
00:02:55,000 --> 00:02:59,000
But we need to be sure that it's triggered only when player enters the trigger.

60
00:02:59,000 --> 00:03:01,000
There are a couple of options to do that.

61
00:03:02,000 --> 00:03:05,000
First, I'm going to show you what mostly people use.

62
00:03:05,000 --> 00:03:07,000
It's a tag comparing so you can do.

63
00:03:07,000 --> 00:03:14,000
If collision collision means the object that collided, the tag equals equals two and you give a name

64
00:03:14,000 --> 00:03:16,000
of a tag, for example player.

65
00:03:17,000 --> 00:03:18,000
Then debug log.

66
00:03:18,000 --> 00:03:18,000
Coin.

67
00:03:18,000 --> 00:03:19,000
Right.

68
00:03:19,000 --> 00:03:22,000
How you assign a tag, you're going back to unity.

69
00:03:22,000 --> 00:03:29,000
Select the object tag and you can choose player here you can see or you can add another new one that

70
00:03:29,000 --> 00:03:29,000
you want.

71
00:03:31,000 --> 00:03:32,000
And it's going to work.

72
00:03:33,000 --> 00:03:36,000
It's going to work for sure, But I want to use a different way.

73
00:03:37,000 --> 00:03:39,000
And just make sure it's working.

74
00:03:40,000 --> 00:03:44,000
So I'm entering the trigger boom coin.

75
00:03:44,000 --> 00:03:44,000
All right.

76
00:03:45,000 --> 00:03:46,000
Let's go back.

77
00:03:46,000 --> 00:03:49,000
I want to use component because I.

78
00:03:49,000 --> 00:03:51,000
This is not my first course.

79
00:03:51,000 --> 00:03:52,000
And even this course.

80
00:03:52,000 --> 00:03:53,000
Exactly.

81
00:03:53,000 --> 00:03:54,000
I'm reworking to make it better.

82
00:03:54,000 --> 00:03:59,000
I'm trying to and I've had issue with the students who couldn't get the name right, like they could

83
00:03:59,000 --> 00:04:06,000
use small p or mix sub the name, misspell whatever, and it causes some confusion and frustration situations,

84
00:04:06,000 --> 00:04:06,000
I would say.

85
00:04:06,000 --> 00:04:11,000
So what I want to do here is not compare in a tag, but to check if object has a component which is

86
00:04:11,000 --> 00:04:13,000
as easy to do as this one.

87
00:04:13,000 --> 00:04:16,000
We can do collision dot get component.

88
00:04:17,000 --> 00:04:24,000
So we check if collision get component of player not equals to null.

89
00:04:26,000 --> 00:04:30,000
Which means there is a player component, which means it is a player.

90
00:04:30,000 --> 00:04:36,000
Then we can do some action and instead of debug this time, let's do game manager dot instance, dot

91
00:04:36,000 --> 00:04:38,000
coins plus plus.

92
00:04:39,000 --> 00:04:43,000
And right after we added a coin, we can destroy the coin as well.

93
00:04:43,000 --> 00:04:49,000
So destroy the game object and it's going to destroy a game object with this script.

94
00:04:49,000 --> 00:04:50,000
And let's go and test this.

95
00:04:50,000 --> 00:04:52,000
I'm going to save the script, go back to Unity.

96
00:04:52,000 --> 00:04:55,000
So my game manager has zero coins.

97
00:04:55,000 --> 00:04:57,000
I'll place coin in a way and I'll try to pick it up.

98
00:04:58,000 --> 00:05:00,000
Boom coin was picked up, It was destroyed.

99
00:05:00,000 --> 00:05:03,000
And my game manager has one coin now.

100
00:05:03,000 --> 00:05:04,000
Perfect.

101
00:05:04,000 --> 00:05:09,000
Now let's select Project folder prefab and drag this coin over here.

102
00:05:10,000 --> 00:05:15,000
After you did this, you can delete Coyne from the hierarchy, and whenever you need to place a new

103
00:05:15,000 --> 00:05:20,000
coin, you can do it just like this or you can place it on a level part.

104
00:05:20,000 --> 00:05:26,000
You can choose level part and just drag coin over here and it's going to be there whenever you instantiate

105
00:05:26,000 --> 00:05:26,000
new level bar.

106
00:05:26,000 --> 00:05:28,000
But we're not going to do it like that.

107
00:05:28,000 --> 00:05:31,000
We're going to create a coin generator right in the next video.

108
00:05:31,000 --> 00:05:32,000
So let's go and do that.

