1 00:00:04,010 --> 00:00:04,820 ‫Welcome back. 2 00:00:04,850 --> 00:00:06,920 ‫In this video, we are going to add the high score. 3 00:00:06,920 --> 00:00:11,720 ‫And as you can see here, we already have this best zero, which is the best score. 4 00:00:11,720 --> 00:00:18,020 ‫And what we'll do is we'll add the functionality so that it actually does something. 5 00:00:18,020 --> 00:00:20,900 ‫So let's go to our game manager in order to do that. 6 00:00:21,320 --> 00:00:25,340 ‫And in there we need to create a new variable. 7 00:00:25,340 --> 00:00:35,510 ‫And I'm going to call that public text, high score text, because we need to somehow access the high 8 00:00:35,510 --> 00:00:38,300 ‫score text and we do that this way. 9 00:00:38,810 --> 00:00:45,920 ‫Next, when in the wake method, I'm going to assign the text of that high score. 10 00:00:46,130 --> 00:00:48,500 ‫And in order to do that, I do the following. 11 00:00:49,160 --> 00:00:52,910 ‫I get the high score, which is actually a new variable. 12 00:00:52,910 --> 00:00:56,750 ‫So let's do that as well, public and high score. 13 00:00:57,320 --> 00:01:02,960 ‫So we need a high score variable, which is just the value as a number and we need the text, which 14 00:01:02,960 --> 00:01:05,210 ‫is the representation on the guy. 15 00:01:05,480 --> 00:01:10,640 ‫And in order to change the high score or assign the high score from the start. 16 00:01:10,640 --> 00:01:20,060 ‫So whenever we start the game, we set the high score to player press, dot, get int and then here 17 00:01:20,060 --> 00:01:23,240 ‫we just enter the key high score. 18 00:01:24,620 --> 00:01:33,560 ‫So the player press is a class which allows us to save very little information so just a very which 19 00:01:33,560 --> 00:01:40,400 ‫stores so the player press is a class which stores and accesses player preferences between game sessions 20 00:01:40,400 --> 00:01:44,390 ‫that's used for for example the preferences that the player has set up. 21 00:01:44,390 --> 00:01:51,620 ‫So let's say the volume or the resolution that he's using or the high score or stuff like that. 22 00:01:51,620 --> 00:01:54,380 ‫And that's perfect for what we want to use. 23 00:01:54,380 --> 00:01:59,090 ‫So it's great to score store information such as integers or strings. 24 00:01:59,330 --> 00:02:01,070 ‫It's not really good for anything else. 25 00:02:01,070 --> 00:02:06,830 ‫So it's just if you look at it, get int, float and string. 26 00:02:06,830 --> 00:02:13,070 ‫So these are the types that you can store within player press and that's how you can get an integer 27 00:02:13,070 --> 00:02:18,080 ‫and the integer that is saved or stored at the key of high score. 28 00:02:18,080 --> 00:02:20,960 ‫So you could enter whatever you want here. 29 00:02:20,990 --> 00:02:27,260 ‫It will check if for that key that you have entered here is anything that is an integer and that can 30 00:02:27,260 --> 00:02:28,940 ‫be fetched or obtained. 31 00:02:28,940 --> 00:02:34,670 ‫Whatever that will be will be initialized or assigned to our high score variable, which is our integer. 32 00:02:34,820 --> 00:02:43,010 ‫And now we can go ahead and set the high score text to the high score. 33 00:02:43,100 --> 00:02:49,160 ‫And the best version here is best empty space and plus high score. 34 00:02:50,840 --> 00:02:53,890 ‫Now this is how we can obtain this score. 35 00:02:53,900 --> 00:02:56,780 ‫But now you might wonder, how do we save the score? 36 00:02:56,810 --> 00:03:02,870 ‫Well, we do that in increased score with a simple if statement here. 37 00:03:02,870 --> 00:03:10,480 ‫We check if our score is higher than the high score. 38 00:03:10,490 --> 00:03:13,430 ‫And if that's the case, then we store this course. 39 00:03:13,430 --> 00:03:21,410 ‫So we use player press to set an integer before we gotten the integer with get integer. 40 00:03:21,410 --> 00:03:27,950 ‫Now we set the integer with set int and in here we just say which key we want to use and we use this 41 00:03:28,040 --> 00:03:31,640 ‫key high score and then the value that we want to store. 42 00:03:31,640 --> 00:03:34,130 ‫And that's going to be our score. 43 00:03:36,310 --> 00:03:41,830 ‫And at the same time we want to apply that to our high score text as well. 44 00:03:41,830 --> 00:03:46,510 ‫So we update our high score text with the latest score. 45 00:03:47,260 --> 00:03:51,490 ‫And of course, that's not a string, so we need to cast it to a string. 46 00:03:52,480 --> 00:03:53,080 ‫All right. 47 00:03:53,080 --> 00:03:57,520 ‫So this is how you save it and that's how you obtain it. 48 00:03:57,520 --> 00:04:00,370 ‫So you need to use the same key that's important. 49 00:04:00,370 --> 00:04:02,290 ‫Otherwise it will not find anything. 50 00:04:02,290 --> 00:04:04,150 ‫And then high score will be empty. 51 00:04:05,410 --> 00:04:14,890 ‫Now let's save that script and let's go back to Unity and run our game, get some points and increase 52 00:04:14,890 --> 00:04:15,430 ‫our score. 53 00:04:15,430 --> 00:04:16,960 ‫Actually, I screwed up there. 54 00:04:17,230 --> 00:04:20,140 ‫Once again, let's get some points. 55 00:04:20,140 --> 00:04:27,040 ‫As you can see, our best is not changed yet and that has to do with us not accessing it. 56 00:04:30,860 --> 00:04:32,180 ‫And let's stop the game. 57 00:04:32,180 --> 00:04:36,230 ‫We can see score is 78, so now the best is still zero. 58 00:04:36,230 --> 00:04:38,120 ‫And that's because we're not assigning it. 59 00:04:38,120 --> 00:04:43,310 ‫So our game manager doesn't have a score or a high score text yet. 60 00:04:43,610 --> 00:04:49,580 ‫So let's get the high score text from our canvas in here and let's drag it in. 61 00:04:49,580 --> 00:04:50,750 ‫So now let's start again. 62 00:04:50,750 --> 00:04:54,140 ‫You might see direct or we should see Directive 78. 63 00:04:54,170 --> 00:04:54,740 ‫There it is. 64 00:04:54,740 --> 00:04:58,610 ‫So 78 is our high score and it's directly assigned to it. 65 00:04:59,060 --> 00:04:59,510 ‫Great. 66 00:04:59,510 --> 00:05:05,030 ‫So what I want to have is that the score goes back to best zero and the score here goes also to zero 67 00:05:05,030 --> 00:05:12,020 ‫whenever we are on the game over screen and I want to see the best score or the high score on our game 68 00:05:12,020 --> 00:05:13,640 ‫over panel as well. 69 00:05:13,640 --> 00:05:23,450 ‫So I'm going to duplicate this game over label score text and I'm going to drag it up and I'm going 70 00:05:23,450 --> 00:05:27,140 ‫to call it game over label, high score text. 71 00:05:27,800 --> 00:05:34,160 ‫So what that should do is it should show the high score and that should be at -120 maybe. 72 00:05:34,160 --> 00:05:43,520 ‫Yeah, that should be fine at -120 and it should not show score, but high score. 73 00:05:44,090 --> 00:05:47,510 ‫So high score is zero. 74 00:05:49,880 --> 00:05:55,430 ‫Now we need, of course, to edit our game manager a little bit in order to make it available as well. 75 00:05:55,430 --> 00:06:00,080 ‫So in here we only had our game over panel score text. 76 00:06:00,080 --> 00:06:01,340 ‫Now we need to game over. 77 00:06:01,340 --> 00:06:03,620 ‫Panel High score text. 78 00:06:06,350 --> 00:06:08,900 ‫And in on Bob hit. 79 00:06:08,930 --> 00:06:13,890 ‫What I want to do is I want to set the game over panel high score to the best score. 80 00:06:13,910 --> 00:06:15,830 ‫So game over, panel. 81 00:06:15,860 --> 00:06:17,330 ‫High score text. 82 00:06:18,410 --> 00:06:25,610 ‫Text is equal to best colon plus high score to string. 83 00:06:26,210 --> 00:06:29,090 ‫So now we do that on bottom hit. 84 00:06:29,100 --> 00:06:33,230 ‫So whenever we hit the bump, we set the score text and the high score text. 85 00:06:33,230 --> 00:06:41,030 ‫And then while we do the high score getting in our wake method, a better version is of course to or 86 00:06:41,030 --> 00:06:44,600 ‫a better way to do that is to have an additional method for that. 87 00:06:44,600 --> 00:06:49,340 ‫So public void get or actually public. 88 00:06:51,240 --> 00:06:59,190 ‫Void, get high score and in here we are simply going to do just that. 89 00:06:59,190 --> 00:07:04,200 ‫So we're going to get the high score and now we can call it in here, get high score. 90 00:07:04,560 --> 00:07:07,440 ‫And actually we don't need to make it public. 91 00:07:07,440 --> 00:07:11,610 ‫It can be private because why would we call it from another class? 92 00:07:11,610 --> 00:07:16,800 ‫If we should want to call it from another class, we could, of course, change it back to to public. 93 00:07:16,800 --> 00:07:21,870 ‫But as we only will use it in our awake method, we can use it or in this class better serve than the 94 00:07:21,870 --> 00:07:22,500 ‫game manager. 95 00:07:22,500 --> 00:07:28,740 ‫We will keep it private now while we are in the game manager, let's clean up the score text, text 96 00:07:28,740 --> 00:07:35,130 ‫as well, because so far we only set it to zero and a better version would be to go ahead and call it 97 00:07:35,130 --> 00:07:36,690 ‫score to string. 98 00:07:36,870 --> 00:07:39,540 ‫So whatever the score is, in this case, it's zero. 99 00:07:39,570 --> 00:07:44,580 ‫We can also just call it coach scoring here and the game over. 100 00:07:44,580 --> 00:07:52,800 ‫Panel Text Score zero is not required anymore because the only way we will do that anyways is when we 101 00:07:52,800 --> 00:08:00,750 ‫hit the BOM, so we won't need to set that back to zero as it will only show the assigned score anyways. 102 00:08:00,900 --> 00:08:01,260 ‫All right. 103 00:08:01,260 --> 00:08:04,230 ‫So now before we test that, let's check out our game manager. 104 00:08:04,230 --> 00:08:06,870 ‫It needs some game over panel, high score. 105 00:08:06,930 --> 00:08:11,760 ‫So game over label high score. 106 00:08:13,830 --> 00:08:15,630 ‫And I call that label high score. 107 00:08:15,660 --> 00:08:19,170 ‫It should be panel high score maybe. 108 00:08:24,090 --> 00:08:31,440 ‫Let's rename those panel score and that one panel high score. 109 00:08:32,910 --> 00:08:34,290 ‫So now let's test that. 110 00:08:36,960 --> 00:08:46,530 ‫Let's hit it and we see best 78, let's restart and we see our score is displayed correctly and we can 111 00:08:48,120 --> 00:08:52,240 ‫kill bombs and boom, I hit the bomb and I it shows the score. 112 00:08:52,260 --> 00:08:53,220 ‫It shows the best. 113 00:08:53,220 --> 00:08:54,750 ‫And I can restart the game. 114 00:08:54,960 --> 00:08:55,360 ‫Great. 115 00:08:55,380 --> 00:08:55,800 ‫Great. 116 00:08:55,800 --> 00:09:03,750 ‫So in the next video, we are going to have a look at creating our own fruits in blender and then afterwards 117 00:09:03,750 --> 00:09:05,580 ‫we will extend the game a little bit.