1 00:00:04,040 --> 00:00:04,430 ‫All right. 2 00:00:04,430 --> 00:00:05,100 ‫Welcome back. 3 00:00:05,120 --> 00:00:10,700 ‫Now let's go to the asset store and import the crystals because we will have crystals that we need to 4 00:00:10,700 --> 00:00:11,370 ‫collect. 5 00:00:11,390 --> 00:00:16,890 ‫A very nice asset for that is stylized Chris Tull. 6 00:00:18,140 --> 00:00:19,310 ‫So let's search for that. 7 00:00:19,310 --> 00:00:20,510 ‫We can find it here. 8 00:00:20,510 --> 00:00:22,750 ‫Low poly or low li poly. 9 00:00:22,760 --> 00:00:26,160 ‫They have created great assets for free, as you can see. 10 00:00:26,180 --> 00:00:29,080 ‫So let's go ahead and import that. 11 00:00:29,090 --> 00:00:33,470 ‫Let's download it and import it into our game. 12 00:00:38,760 --> 00:00:41,270 ‫All right, now let's create a crystal prefab out of it. 13 00:00:41,310 --> 00:00:43,640 ‫So let's go to stylized crystal. 14 00:00:43,650 --> 00:00:45,420 ‫We can find a crystal here. 15 00:00:45,510 --> 00:00:47,640 ‫So I'm going to drag that into the game. 16 00:00:48,270 --> 00:00:49,740 ‫As you can see, it has an animator. 17 00:00:49,770 --> 00:00:53,550 ‫We won't need that because we don't want the crystal to be animated. 18 00:00:53,970 --> 00:00:55,650 ‫So let's remove that. 19 00:00:56,860 --> 00:00:58,060 ‫Component. 20 00:00:58,960 --> 00:01:02,230 ‫Now let's change the name to Crystal. 21 00:01:05,090 --> 00:01:12,380 ‫And let's add a box collider So physics box collider And then we set that to trigger. 22 00:01:12,380 --> 00:01:14,180 ‫So it's trigger we set that to true. 23 00:01:14,180 --> 00:01:18,500 ‫So as soon as we collide with that one, we want to add a point to our game. 24 00:01:19,130 --> 00:01:21,500 ‫Now I want to add a tag to this crystal. 25 00:01:21,500 --> 00:01:27,170 ‫So let's add a new tag plus and let's call that one crystal. 26 00:01:27,890 --> 00:01:31,970 ‫And now let's go to the crystal again and select that tag. 27 00:01:33,290 --> 00:01:44,870 ‫Right now, let's create a new folder called Prefabs, Create Folder Prefabs and drag the crystal into 28 00:01:44,870 --> 00:01:46,220 ‫our prefabs folder. 29 00:01:47,750 --> 00:01:52,970 ‫All right, next, I would like to rotate it a little bit and to change the position. 30 00:01:52,970 --> 00:01:57,530 ‫So let's change position to 000 for our crystal. 31 00:01:57,740 --> 00:01:59,660 ‫Actually, for that crystal here. 32 00:01:59,660 --> 00:02:05,720 ‫So 000, as you can see now, it's at the bottom and the Y value I want to have is 0.5. 33 00:02:05,720 --> 00:02:14,570 ‫So now it's just on top of our road and now we need to change its rotation because now you see it has 34 00:02:14,570 --> 00:02:16,670 ‫no rotation, but that's local. 35 00:02:16,670 --> 00:02:24,320 ‫So if we go to global and change it, well, actually I want to have a rotation of 45. 36 00:02:24,710 --> 00:02:30,320 ‫So now let's go to local again and we can move it around again with shift command. 37 00:02:30,320 --> 00:02:32,150 ‫We can position it correctly. 38 00:02:32,150 --> 00:02:40,070 ‫So now let's save that setting and let's apply it to our prefab and now we can go ahead and duplicate 39 00:02:40,070 --> 00:02:40,490 ‫it. 40 00:02:40,940 --> 00:02:51,290 ‫So let's duplicate that crystal duplicate and let's move the duplicate, let's say around here and you 41 00:02:51,290 --> 00:02:57,350 ‫can play around with the values you could, for example, position one here and then duplicate again 42 00:02:57,350 --> 00:03:04,400 ‫and position it just at the edge so that it's quite difficult to get it and you risk of dropping or 43 00:03:04,400 --> 00:03:08,600 ‫falling to the ground or dying and losing the game pretty much. 44 00:03:08,600 --> 00:03:11,600 ‫So you could do that and make it a bit more difficult. 45 00:03:11,600 --> 00:03:15,860 ‫Now, the next thing is, I don't want to have a bunch of crystals in my game. 46 00:03:15,860 --> 00:03:19,310 ‫What I do want to have, however, is a folder. 47 00:03:19,310 --> 00:03:23,330 ‫Well, I want to have them in a game, but I don't want them to be in the hierarchy just like that. 48 00:03:23,330 --> 00:03:26,720 ‫I want them to be in a crystals folder. 49 00:03:26,720 --> 00:03:32,720 ‫So let's drag those crystals into our crystals folder. 50 00:03:36,030 --> 00:03:36,300 ‫Now. 51 00:03:36,300 --> 00:03:37,050 ‫Let's check it out. 52 00:03:37,050 --> 00:03:39,510 ‫Let's see if we can walk through the crystals. 53 00:03:41,370 --> 00:03:45,480 ‫And we can see we can walk through the crystals real quick and perfectly so. 54 00:03:45,480 --> 00:03:50,670 ‫Now if we walk through them, we of course want them to disappear and we want to increase our score. 55 00:03:51,720 --> 00:03:56,930 ‫There's one little thing that I would like to change before we do the crystal implementation even further. 56 00:03:56,940 --> 00:03:59,110 ‫So there is one thing we can still do. 57 00:03:59,130 --> 00:04:04,230 ‫We can still change the rotation of our game before we start the game so we can move our player to the 58 00:04:04,230 --> 00:04:04,770 ‫left. 59 00:04:04,770 --> 00:04:08,190 ‫And if I press enter now, that's not really great behavior. 60 00:04:08,190 --> 00:04:15,870 ‫So what we can do now is we can go back to our script, to our chart controller to be precise, and 61 00:04:15,870 --> 00:04:26,550 ‫within the switch method, we can go ahead and check if the game manager thought game started is false, 62 00:04:27,480 --> 00:04:29,520 ‫then we just want to return. 63 00:04:29,640 --> 00:04:33,180 ‫So that means we will do nothing of those switching. 64 00:04:33,780 --> 00:04:36,930 ‫By that I mean changing the rotation of our player. 65 00:04:37,650 --> 00:04:39,390 ‫So now let's check that one out. 66 00:04:39,720 --> 00:04:44,430 ‫So before the game starts, as you can see, I press my space key and nothing happens. 67 00:04:44,430 --> 00:04:47,490 ‫As soon as I press enter, however, I can do the rotation. 68 00:04:47,670 --> 00:04:48,240 ‫All right. 69 00:04:48,660 --> 00:04:48,930 ‫All right. 70 00:04:48,930 --> 00:04:53,190 ‫So now let's go to our game manager, because we need to have a score. 71 00:04:53,340 --> 00:05:02,540 ‫So let's create a public int called score and we will need a method to increase the score. 72 00:05:02,550 --> 00:05:10,500 ‫So public void increase score and we simply will increase the score by one. 73 00:05:10,680 --> 00:05:12,060 ‫Nothing too fancy. 74 00:05:12,180 --> 00:05:16,260 ‫As soon as we run through an object, we want to increase increase the score by one. 75 00:05:16,920 --> 00:05:18,870 ‫And when do we want to call this method? 76 00:05:19,020 --> 00:05:28,050 ‫Well, in our character controller and there we will need an on trigger enter call. 77 00:05:28,050 --> 00:05:29,870 ‫So we need the method on trigger enter. 78 00:05:29,880 --> 00:05:41,070 ‫So as soon as we collide with something and that something so other dot tag is equal to crystal, then 79 00:05:41,070 --> 00:05:43,530 ‫we want to destroy the object. 80 00:05:43,530 --> 00:05:49,380 ‫So destroy our other game object, which means we will destroy the crystal. 81 00:05:49,380 --> 00:05:55,680 ‫And then we want to increase the score, which means we call the increase score method. 82 00:05:56,730 --> 00:06:02,730 ‫All right, so let's try that and what we will not see. 83 00:06:02,730 --> 00:06:06,720 ‫Well, we will collect those objects, so let's press enter. 84 00:06:07,090 --> 00:06:12,020 ‫As you can see, we destroy the game objects, but we don't see the score yet. 85 00:06:12,030 --> 00:06:13,500 ‫So for you, a little challenge. 86 00:06:13,500 --> 00:06:16,650 ‫Please add a UI element to the top left. 87 00:06:16,650 --> 00:06:20,340 ‫So just a number showing us how many points we have. 88 00:06:20,340 --> 00:06:22,890 ‫So just show the score on the top left side. 89 00:06:23,220 --> 00:06:23,940 ‫Try that. 90 00:06:23,940 --> 00:06:25,260 ‫Please go ahead and do that. 91 00:06:26,910 --> 00:06:27,240 ‫All right. 92 00:06:27,240 --> 00:06:28,290 ‫I hope you tried it. 93 00:06:28,290 --> 00:06:32,910 ‫So let's create a new UI text in our hierarchy. 94 00:06:33,320 --> 00:06:35,760 ‫Now, as you can see, a canvas is created for us. 95 00:06:35,910 --> 00:06:37,950 ‫Now let's click on the text variable. 96 00:06:37,950 --> 00:06:40,020 ‫I want it to be at the top left. 97 00:06:40,020 --> 00:06:42,540 ‫So I set an anchor to the top left. 98 00:06:42,900 --> 00:06:48,300 ‫Now let's set the position to, let's say 100 and let's go with zero. 99 00:06:48,300 --> 00:06:50,070 ‫Now, just to see where it goes. 100 00:06:50,430 --> 00:06:56,340 ‫Then let's change the font size to let's go with 50 the color. 101 00:06:56,340 --> 00:06:58,470 ‫I want it to be a white text. 102 00:06:58,980 --> 00:07:05,070 ‫Then as a horizontal overflow and the vertical overflow, I'm going to use overflow, which means it 103 00:07:05,070 --> 00:07:10,320 ‫will go outside of its size, which is height 30 if it needs to. 104 00:07:10,320 --> 00:07:14,460 ‫So if it needs more space, then it will simply take the space. 105 00:07:14,700 --> 00:07:21,360 ‫And now let's set the number to zero and let's see how that looks in our game. 106 00:07:21,360 --> 00:07:22,230 ‫All right, there we are. 107 00:07:22,230 --> 00:07:25,620 ‫So maybe zero is not the perfect Y position. 108 00:07:25,620 --> 00:07:28,980 ‫So let's move that a little bit. 109 00:07:31,260 --> 00:07:36,330 ‫Maybe two -50 or maybe -20 is enough. 110 00:07:36,330 --> 00:07:36,960 ‫All right. 111 00:07:36,960 --> 00:07:39,120 ‫And the X position. 112 00:07:39,300 --> 00:07:42,360 ‫Let's go with 100. 113 00:07:42,690 --> 00:07:45,000 ‫Maybe the font size should be a bit higher. 114 00:07:45,000 --> 00:07:50,070 ‫So let's go with 100 here for the font size, you could of course use a different font. 115 00:07:50,340 --> 00:07:53,100 ‫I'm just going to use Arial for now. 116 00:07:53,100 --> 00:07:56,220 ‫And yeah, I think that should be good. 117 00:07:56,580 --> 00:08:04,350 ‫Now let's see what happens if we start the game and we try to score. 118 00:08:05,400 --> 00:08:10,740 ‫Of course nothing happens because we haven't implemented it, so I hope you try to implement it as well. 119 00:08:10,740 --> 00:08:16,710 ‫By the way, let's change the name of the text to score text just to show that the names are right now 120 00:08:16,710 --> 00:08:18,450 ‫in our game manager. 121 00:08:18,450 --> 00:08:20,190 ‫We will need to change some things. 122 00:08:20,190 --> 00:08:22,140 ‫We will need to have the text. 123 00:08:22,140 --> 00:08:29,130 ‫So that means we need using unity engine UI in order to access the text class. 124 00:08:29,400 --> 00:08:33,510 ‫And now we need a public text score text. 125 00:08:35,220 --> 00:08:46,160 ‫And with an increased score we also set the score text that text variable or text property to score 126 00:08:46,260 --> 00:08:48,540 ‫dot to string. 127 00:08:48,810 --> 00:08:54,960 ‫So that means we transform our score value, which is zero at the beginning, and then it goes up and 128 00:08:54,960 --> 00:08:55,380 ‫up. 129 00:08:55,590 --> 00:08:57,630 ‫We convert that to a string. 130 00:08:58,530 --> 00:08:58,890 ‫All right. 131 00:08:58,890 --> 00:09:00,300 ‫So let's save that script. 132 00:09:01,380 --> 00:09:10,110 ‫Let's go to our game manager, because now our game manager will also need a text after a little while 133 00:09:10,110 --> 00:09:11,760 ‫so that we are score text. 134 00:09:11,770 --> 00:09:16,440 ‫Now let's drag that score text in here and now let's try it again. 135 00:09:18,920 --> 00:09:19,550 ‫Enter. 136 00:09:19,550 --> 00:09:23,240 ‫And as you can see, we're collecting points. 137 00:09:23,930 --> 00:09:24,650 ‫Perfect. 138 00:09:25,640 --> 00:09:30,080 ‫In the next video, we are going to have a look at setting up the high score. 139 00:09:30,090 --> 00:09:33,970 ‫So we want to know what the high score is, how far could we go? 140 00:09:33,980 --> 00:09:35,360 ‫So see in the next video.