Welcome back.
In this video, we'll prepare our code so that the game will run on Android as well, because so far
we are using the mouse and if we don't move the mouse at all.
So for example, I don't move the mouse now, but still my fruit day fruits get destroyed.
So whenever I touch something or the mouse touches something, then the object gets destroyed or touched.
So what I want to have is that my object only or my my blade only is active.
If I actually moved the mouse a little bit or if I touched with my finger a little bit.
So if I swipe just a little bit, then life is active.
If I didn't touch it, then there is no no knife and I don't destroy anything or touch anything.
So let's do that.
Let's go back to our code and we handle that within our blade.
So far we always took the mouse position, but now what we will need to do is check if our mouse is
moving.
So we'll need to have the last mouse position.
We will need to have the mouse velocity and the minimum velocity that we want to have so that we say
that this is an actual movement of the mouse.
So let's say if the mouse moves just just a little, little bit, we don't want that to be an actual
movement so we can set up how much movement we require for it to be an actual mouse movement.
So let's create those variables that we'll need.
First of all, a public variable that I'm going to call Min Velo, which stands for minimum velocity,
and I'm going to use 0.1 as its value, 0.1 float.
So we're going to use a float value here.
Then I need several private variables, so I need a private vector three, which is our last mouse position
and a private vector three, which is our mouse velocity.
And finally we need a private collider to DH, which is our call.
So that's just going to be a2d collider and in our wake method we will initialize that collider.
So call is get component and the collider.
So we want to have the collider to DX of our blade.
That's what we ask for here.
Now our collider should only be active if we are moving our mouse or if we are touching the screen.
So that's the idea behind this collider, because if we look at the collider of our blade, I'm going
to pause the game or stop the game here.
Our blade has a collider.
Let me crop that.
So here this circle collider to DX is the collider of our blade.
And I only want this to be active if our mouse is moving.
So let's create a new method for that and it's going to return a boolean.
We're just going to say, is mouse moving?
You could also call it is thing moving or something comparable.
So we are going to set the vector three here, which we call current mouse position and that's going
to be the current position of our blade.
Next, we calculate how much it has traveled.
So traveled is going to be the last mouse position minus the current mouse position.
And then we use magnitude here.
So we, we apply the dot magnitude property here, returns the length of this vector.
And what that will do is it will simply tell us the length between last mouse position and current mouse
position, because those are two points in a 3D world and there is a line between those and I want to
have the length of that line and that's what magnitude will return.
Now I can simply say the last mouse position is the current mouse position, because we have here this
last mouse position, this private variable, and each time we move our mouse we want, we will update
that.
So each time is move its mouse moving is called that one will be updated.
So we calculate how much we have traveled and then we update our last mouse position variable.
So now what we need to check if traveled.
So the distance that was traveled is bigger than the min velocity.
Then we want to return.
True, and otherwise we return false.
So what that means is if we actually.
We don't need those if.
We have traveled enough space.
So if the mouse has traveled enough space, then return true.
If it hasn't return false.
And what is enough space or what is enough distance?
Well, that's whatever we have set up here.
So min velocity 0.1 F.
Now what we all need to do is in the update method we will need to assign our call to enabled variable
two is mouse moving.
So only if we have touched the screen and moved our screen our mouse a little bit, only then our call
will be enabled.
So that means our collider two dx of our blade will then be enabled.
So now let's save that script and let's go back to our game and let's see if we still destroy objects,
if we don't move the mouse.
As you can see, the objects fly through.
I don't damage them, but as soon as I move my mouse.
Just a little bit.
Now I don't move it.
As you can see, the fruits don't get destroyed.
I moved it a little bit and my fruits get destroyed.
So while I'm moving, it gets destroyed.
Otherwise it doesn't get destroyed or the.
The fruits don't get cut.
Great.
So now we're ready.
So see you in the next video where we're going to set up our Android studio and prepare everything so
that we can go ahead for Android.
We prepared already the code.
So let's go ahead in the next video and prepare the rest.