1 00:00:04,140 --> 00:00:04,940 ‫We'll come back. 2 00:00:04,950 --> 00:00:13,310 ‫And this video I want to introduce classes to you that we have not used yet, but that we can use. 3 00:00:13,320 --> 00:00:19,050 ‫And in general, I want to show you that there are classes which you can use in order to have functionality 4 00:00:19,050 --> 00:00:21,060 ‫that you don't have to write yourself. 5 00:00:21,330 --> 00:00:27,600 ‫So one thing that is used very regularly, which is very important in most of the video games, is a 6 00:00:27,600 --> 00:00:29,170 ‫random factor. 7 00:00:29,190 --> 00:00:34,830 ‫You need to have some sort of randomness sometimes in order to make the game fun because it's unpredictable 8 00:00:34,830 --> 00:00:35,840 ‫what happens next. 9 00:00:35,850 --> 00:00:40,880 ‫And if you want to do that, you don't have to write the random functionality yourself. 10 00:00:40,890 --> 00:00:47,490 ‫You can simply use a class which is built in into C-sharp or in this case into unity. 11 00:00:47,490 --> 00:00:52,110 ‫So there is a different type of this random class that unity uses. 12 00:00:52,110 --> 00:00:54,180 ‫So let's go with random. 13 00:00:54,420 --> 00:00:58,020 ‫So what it does is class for generating random data. 14 00:00:58,020 --> 00:01:00,210 ‫So there is a class called random. 15 00:01:00,210 --> 00:01:08,850 ‫And if we press the dot button, we can see the different methods and the different properties that 16 00:01:08,850 --> 00:01:11,250 ‫this class has to offer. 17 00:01:11,250 --> 00:01:15,580 ‫So for example, it has to offer a range with this or a range method. 18 00:01:15,600 --> 00:01:23,040 ‫What this does is it returns a float value, which is a random value between a minimum and a maximum 19 00:01:23,040 --> 00:01:25,830 ‫value that you can assign yourself. 20 00:01:25,980 --> 00:01:36,630 ‫So if I do that, for example, let's go ahead and I say I want to have a value between zero and 15. 21 00:01:38,820 --> 00:01:42,990 ‫So I said float min is zero and float max is 15. 22 00:01:43,440 --> 00:01:50,820 ‫And what I want to do with this is I want to save it in a variable, so let's save it in a float, my 23 00:01:50,820 --> 00:01:57,390 ‫random number, and now let's print that out. 24 00:01:57,600 --> 00:01:59,970 ‫So backlog my random number. 25 00:02:00,960 --> 00:02:10,500 ‫Now doing that in the start method is great, but doing it in the update method is maybe a bit more 26 00:02:10,500 --> 00:02:11,040 ‫interesting. 27 00:02:11,040 --> 00:02:12,720 ‫So let's do that. 28 00:02:12,720 --> 00:02:18,870 ‫Let's create a new random number every single time and let's print it on the screen and it will create 29 00:02:18,870 --> 00:02:20,430 ‫loads of random numbers. 30 00:02:20,430 --> 00:02:23,850 ‫So let's just have a look what that does. 31 00:02:27,370 --> 00:02:27,670 ‫All right. 32 00:02:27,670 --> 00:02:28,150 ‫So there we are. 33 00:02:28,150 --> 00:02:33,850 ‫We get a random number regularly already, 100 and so many numbers. 34 00:02:33,850 --> 00:02:35,410 ‫So let's pause the game. 35 00:02:35,530 --> 00:02:42,330 ‫And as you can see, the number that we get is 11.6, 6.3, 9.1 and so on. 36 00:02:42,340 --> 00:02:47,380 ‫So I get numbers between zero and 15 and they are completely random. 37 00:02:47,500 --> 00:02:50,290 ‫Well, at least there is random as a computer can create them. 38 00:02:50,530 --> 00:02:54,100 ‫And that's quite some randomness that we get here. 39 00:02:54,100 --> 00:03:00,310 ‫And that's a functionality that you might use very often based on the games that you want to build. 40 00:03:03,790 --> 00:03:09,900 ‫Now, another thing that you might want to use is the math class and the math class. 41 00:03:09,910 --> 00:03:17,200 ‫In this case, it's a strict math F and the struct contains a collection of common math functions. 42 00:03:17,200 --> 00:03:18,940 ‫So let's have a look at the math. 43 00:03:19,150 --> 00:03:24,010 ‫If we press the dot, we can see all those properties and methods. 44 00:03:24,010 --> 00:03:31,510 ‫So here we have apps that if you want to get an absolute number across coziness, if you want to have 45 00:03:31,510 --> 00:03:36,850 ‫a arc cosine of f well plenty of math methods. 46 00:03:36,850 --> 00:03:42,310 ‫These are quite useful if you want to do something with angles. 47 00:03:42,310 --> 00:03:47,380 ‫If you want to change the angle or calculate the angle, then if you want to round something down, 48 00:03:47,380 --> 00:03:48,520 ‫you could use floor. 49 00:03:48,520 --> 00:03:52,480 ‫If you want to use the exponential, you could use x, p and so forth. 50 00:03:52,480 --> 00:03:58,720 ‫So you can see you have all the different methods in here, pow, syn sine, smooth step, all those 51 00:03:58,720 --> 00:03:59,500 ‫kind of things. 52 00:03:59,500 --> 00:04:02,320 ‫So I'm not going to go through all of them just for you. 53 00:04:02,320 --> 00:04:06,850 ‫So you know that there is something that will make your job a lot easier. 54 00:04:06,850 --> 00:04:12,220 ‫So this is what I highly recommend whenever you're in a situation where you think, All right, well, 55 00:04:12,220 --> 00:04:17,110 ‫I want to do A, B, C, is there a way to do that easily? 56 00:04:17,110 --> 00:04:20,760 ‫So don't try to write complex, highly complex code. 57 00:04:20,770 --> 00:04:23,080 ‫First of all, check out Google. 58 00:04:23,080 --> 00:04:24,430 ‫Just have a quick look. 59 00:04:24,430 --> 00:04:29,320 ‫Maybe you can find something, do some research before you do hours of programming. 60 00:04:29,320 --> 00:04:29,680 ‫All right. 61 00:04:29,680 --> 00:04:35,440 ‫So the math F function, for example, is very powerful to help you with whatever has to do with math. 62 00:04:35,440 --> 00:04:40,120 ‫And there might be classes that I'm not covering in the course which will be very useful to you. 63 00:04:40,120 --> 00:04:46,360 ‫So always have a look at which classes are available and which can help you based on the situation that 64 00:04:46,360 --> 00:04:46,810 ‫you're at. 65 00:04:47,680 --> 00:04:48,280 ‫All right. 66 00:04:48,280 --> 00:04:50,650 ‫So that's it for this video. 67 00:04:50,650 --> 00:04:56,740 ‫Please check out the math class, check out the random class, use them, try them and see you in the 68 00:04:56,740 --> 00:04:57,670 ‫next video.