1 00:00:04,100 --> 00:00:05,090 ‫Welcome back. 2 00:00:05,120 --> 00:00:11,270 ‫In this video, we'll prepare our code so that the game will run on Android as well, because so far 3 00:00:11,270 --> 00:00:15,200 ‫we are using the mouse and if we don't move the mouse at all. 4 00:00:15,200 --> 00:00:21,110 ‫So for example, I don't move the mouse now, but still my fruit day fruits get destroyed. 5 00:00:21,110 --> 00:00:27,880 ‫So whenever I touch something or the mouse touches something, then the object gets destroyed or touched. 6 00:00:27,890 --> 00:00:33,920 ‫So what I want to have is that my object only or my my blade only is active. 7 00:00:34,220 --> 00:00:38,960 ‫If I actually moved the mouse a little bit or if I touched with my finger a little bit. 8 00:00:38,960 --> 00:00:41,990 ‫So if I swipe just a little bit, then life is active. 9 00:00:41,990 --> 00:00:47,600 ‫If I didn't touch it, then there is no no knife and I don't destroy anything or touch anything. 10 00:00:48,290 --> 00:00:49,640 ‫So let's do that. 11 00:00:49,640 --> 00:00:53,630 ‫Let's go back to our code and we handle that within our blade. 12 00:00:53,630 --> 00:00:59,780 ‫So far we always took the mouse position, but now what we will need to do is check if our mouse is 13 00:00:59,780 --> 00:01:00,200 ‫moving. 14 00:01:00,200 --> 00:01:04,130 ‫So we'll need to have the last mouse position. 15 00:01:04,130 --> 00:01:12,050 ‫We will need to have the mouse velocity and the minimum velocity that we want to have so that we say 16 00:01:12,050 --> 00:01:14,990 ‫that this is an actual movement of the mouse. 17 00:01:14,990 --> 00:01:20,630 ‫So let's say if the mouse moves just just a little, little bit, we don't want that to be an actual 18 00:01:20,630 --> 00:01:27,500 ‫movement so we can set up how much movement we require for it to be an actual mouse movement. 19 00:01:27,500 --> 00:01:29,960 ‫So let's create those variables that we'll need. 20 00:01:29,960 --> 00:01:37,820 ‫First of all, a public variable that I'm going to call Min Velo, which stands for minimum velocity, 21 00:01:37,910 --> 00:01:43,580 ‫and I'm going to use 0.1 as its value, 0.1 float. 22 00:01:43,760 --> 00:01:45,530 ‫So we're going to use a float value here. 23 00:01:45,860 --> 00:01:56,930 ‫Then I need several private variables, so I need a private vector three, which is our last mouse position 24 00:01:57,110 --> 00:02:03,770 ‫and a private vector three, which is our mouse velocity. 25 00:02:04,580 --> 00:02:10,490 ‫And finally we need a private collider to DH, which is our call. 26 00:02:10,490 --> 00:02:19,490 ‫So that's just going to be a2d collider and in our wake method we will initialize that collider. 27 00:02:19,520 --> 00:02:23,840 ‫So call is get component and the collider. 28 00:02:23,840 --> 00:02:27,980 ‫So we want to have the collider to DX of our blade. 29 00:02:29,420 --> 00:02:31,340 ‫That's what we ask for here. 30 00:02:32,210 --> 00:02:39,080 ‫Now our collider should only be active if we are moving our mouse or if we are touching the screen. 31 00:02:39,080 --> 00:02:44,690 ‫So that's the idea behind this collider, because if we look at the collider of our blade, I'm going 32 00:02:44,690 --> 00:02:46,310 ‫to pause the game or stop the game here. 33 00:02:46,310 --> 00:02:48,080 ‫Our blade has a collider. 34 00:02:48,350 --> 00:02:50,630 ‫Let me crop that. 35 00:02:50,630 --> 00:02:55,100 ‫So here this circle collider to DX is the collider of our blade. 36 00:02:55,100 --> 00:02:59,330 ‫And I only want this to be active if our mouse is moving. 37 00:03:00,230 --> 00:03:07,040 ‫So let's create a new method for that and it's going to return a boolean. 38 00:03:07,130 --> 00:03:11,330 ‫We're just going to say, is mouse moving? 39 00:03:12,320 --> 00:03:17,210 ‫You could also call it is thing moving or something comparable. 40 00:03:17,210 --> 00:03:24,320 ‫So we are going to set the vector three here, which we call current mouse position and that's going 41 00:03:24,320 --> 00:03:28,430 ‫to be the current position of our blade. 42 00:03:30,080 --> 00:03:33,650 ‫Next, we calculate how much it has traveled. 43 00:03:33,650 --> 00:03:40,280 ‫So traveled is going to be the last mouse position minus the current mouse position. 44 00:03:40,940 --> 00:03:44,990 ‫And then we use magnitude here. 45 00:03:45,260 --> 00:03:51,200 ‫So we, we apply the dot magnitude property here, returns the length of this vector. 46 00:03:51,200 --> 00:03:58,550 ‫And what that will do is it will simply tell us the length between last mouse position and current mouse 47 00:03:58,550 --> 00:04:04,640 ‫position, because those are two points in a 3D world and there is a line between those and I want to 48 00:04:04,960 --> 00:04:09,830 ‫have the length of that line and that's what magnitude will return. 49 00:04:11,090 --> 00:04:18,650 ‫Now I can simply say the last mouse position is the current mouse position, because we have here this 50 00:04:19,040 --> 00:04:25,640 ‫last mouse position, this private variable, and each time we move our mouse we want, we will update 51 00:04:25,640 --> 00:04:26,120 ‫that. 52 00:04:26,210 --> 00:04:30,710 ‫So each time is move its mouse moving is called that one will be updated. 53 00:04:30,710 --> 00:04:37,070 ‫So we calculate how much we have traveled and then we update our last mouse position variable. 54 00:04:37,460 --> 00:04:41,030 ‫So now what we need to check if traveled. 55 00:04:41,840 --> 00:04:47,090 ‫So the distance that was traveled is bigger than the min velocity. 56 00:04:49,040 --> 00:04:51,140 ‫Then we want to return. 57 00:04:51,140 --> 00:04:56,600 ‫True, and otherwise we return false. 58 00:04:59,870 --> 00:05:02,120 ‫So what that means is if we actually. 59 00:05:02,120 --> 00:05:03,440 ‫We don't need those if. 60 00:05:03,550 --> 00:05:06,310 ‫We have traveled enough space. 61 00:05:06,310 --> 00:05:10,870 ‫So if the mouse has traveled enough space, then return true. 62 00:05:10,900 --> 00:05:12,430 ‫If it hasn't return false. 63 00:05:12,430 --> 00:05:15,580 ‫And what is enough space or what is enough distance? 64 00:05:15,760 --> 00:05:17,500 ‫Well, that's whatever we have set up here. 65 00:05:17,500 --> 00:05:19,630 ‫So min velocity 0.1 F. 66 00:05:22,360 --> 00:05:31,330 ‫Now what we all need to do is in the update method we will need to assign our call to enabled variable 67 00:05:31,360 --> 00:05:34,060 ‫two is mouse moving. 68 00:05:34,060 --> 00:05:41,830 ‫So only if we have touched the screen and moved our screen our mouse a little bit, only then our call 69 00:05:41,830 --> 00:05:42,640 ‫will be enabled. 70 00:05:42,640 --> 00:05:47,320 ‫So that means our collider two dx of our blade will then be enabled. 71 00:05:47,320 --> 00:05:56,590 ‫So now let's save that script and let's go back to our game and let's see if we still destroy objects, 72 00:05:56,590 --> 00:05:57,670 ‫if we don't move the mouse. 73 00:05:57,670 --> 00:05:59,980 ‫As you can see, the objects fly through. 74 00:05:59,980 --> 00:06:03,460 ‫I don't damage them, but as soon as I move my mouse. 75 00:06:04,710 --> 00:06:05,850 ‫Just a little bit. 76 00:06:06,060 --> 00:06:06,890 ‫Now I don't move it. 77 00:06:06,900 --> 00:06:08,470 ‫As you can see, the fruits don't get destroyed. 78 00:06:08,490 --> 00:06:12,060 ‫I moved it a little bit and my fruits get destroyed. 79 00:06:12,870 --> 00:06:15,390 ‫So while I'm moving, it gets destroyed. 80 00:06:15,390 --> 00:06:17,830 ‫Otherwise it doesn't get destroyed or the. 81 00:06:18,080 --> 00:06:19,440 ‫The fruits don't get cut. 82 00:06:22,650 --> 00:06:23,010 ‫Great. 83 00:06:23,010 --> 00:06:24,220 ‫So now we're ready. 84 00:06:24,240 --> 00:06:29,880 ‫So see you in the next video where we're going to set up our Android studio and prepare everything so 85 00:06:29,880 --> 00:06:31,320 ‫that we can go ahead for Android. 86 00:06:31,320 --> 00:06:32,940 ‫We prepared already the code. 87 00:06:32,940 --> 00:06:35,730 ‫So let's go ahead in the next video and prepare the rest.