Hello, guys, and welcome back.
In this video, we're going to add in the actual touching functionality for the ability.
So when we click on it, we'll or press on it with our finger tip.
We need to see that ability being actually casted.
Okay.
Now the first thing we need to do then is to go to the ability dock and we need to actually make it
to be able to receive the touch input.
Okay.
Now, if you recall right, the other place we did that is based on is on the the joystick.
Right.
And we were able to do that by implementing some or some of the interfaces that the event system supports.
So we need to, first of all, using the unity engine dot event systems.
Oops.
Systems.
Okay.
The even system will be able to support things like touching and inputs, things like that.
And the one we're going to look for is going to look for is the I pointer.
Down handle and then I pointer up handle.
Okay.
And now we need to implement the interface.
Just alt enter and enter again to implement the interface.
All right.
So we're going to try to detect what's underneath the fingertip.
And to do that, we need to make sure that we know where the fingertip is.
And that's easy to find because that's basically the even data.
And let's store that into a variable and call this guy pointer event data.
And because sky touch data, something like that.
Okay.
And the touch data, of course, will be in here equals to the event data.
Okay.
Now when the pointer is up then we'll say the touch data equals to null because that's when it's no
longer being touched.
Okay.
All right.
And then before we do that, we also want to make sure that we know exactly what we're touching at the
moment.
Right.
So let me have a function to retrieve what's underneath the fingertip.
Okay.
And we're going to call this guy.
Can be void.
Get on the pointer or let's let's just have a Boolean there in case we need to know.
Are we finding something or not?
Get UI.
Under Ponta, maybe.
Right.
And here is where we need to take that Ponta even data.
I'm going to call this guy event data and then we're going to output a ability UI and this is going
to be the ability UI.
All right.
Now to do the testing, we can just ask the event system.
Dot current and then we can do the recast.
Recast or.
Recast or a lowercase C, This will recast through a EVENTDATA.
And then spit out a list of request results.
So we need to make the list first.
List recast result in the sky fund.
Ability right equals to new recast results.
And we just pass that in because this is an out parameter.
Okay.
All right.
Now you can see how this is really compatible.
We the pointer even data that we can retrieve from the pointer Dom can be used in here to find out hey
what's what's actually underneath it by just asking the event system to take that data and then spit
out the list of request result.
Okay.
Now we can start with a.
Uh, ability.
Oh, actually, I wanted to hold that into a reference.
Mikulski highlighted ability or something like that.
Okay.
And this of course, starts with nor.
Okay.
And then we just go here to the very bottom.
Uh, we're going to say the ability.
And because we need to have that to be the parameter, we can we can use that for now, but eventually
we'll have that value being assigned to our ability.
Highlighted ability.
All right.
So back here, ability UI will be equal to null first and we need to for each through the raycast result.
Results in the fend ability.
Let's see if we're able to fend in one of them being the ability.
All right.
So to do that, we need to say ability would just be equals to the result dot game object dot get component.
But we want to we need to actually do get component in parent because the component we're going to get
if you test it will be the image of the ability UI, which doesn't really contain the ability class.
After the UI class, but rather the parent has it.
So we need to get it from the parent.
Okay.
Now if we're able to find something.
If this ability UI is not equal to null, that means hey, there is actually an ability UI we're touching,
which is return true.
And then if everything is checked without finding one, we have to return false.
Okay.
All right.
Uh, so that should be it.
Something wrong here?
Oh, well.
That should be the one we're checking against.
Okay.
We're assigning.
So basically, we're giving it a null value here.
First, we loop through everything, and then if we do find some, then it's no longer null.
We will just return.
But if we cannot find any ability underneath the request, which is everything underneath the fingertip,
we return False.
All right.
That'll be our logic here.
Okay, Now, where do we call this function?
Well, we will call this function here in the update guy under pointer.
But we'll have one condition, though.
The condition will be if we do have the touch data before we.
Do this.
So if the touch data is not equal to null, then we will get the UI right underneath the pointer and
that UI.
It will be the one that's the highlighted.
Ability.
The first argument is even the touch data.
Second thing.
Second thing will be our highlighted ability.
Right.
Uh, ability.
Highlighted ability should be the one.
Oh, we need to pass in.
Out.
All right.
So that way in the update, we constantly are trying to find that highlighted ability.
Okay.
All right.
Now, when the, um, pointer down is opened up is called.
Right.
We need to before we set it to null.
Right.
We need to say if the highlighted ability is there, then we'll be asking that ability to be activated.
Right.
And let's just call this activate ability.
Of course, we don't have that function there, but that should be very easy to do.
We just need to implement it because this is the class we were doing earlier, we're working on earlier
and a simple it's a very simple implementation.
We just have to ask the ability to be activated, right?
All right.
Now over here, you can see now we are activating the ability, but we never do anything in the cooldown.
Right?
So we can actually start implementing the cooldown part here as well.
So we need to first check if we are on cooldown.
Right, which is the boolean we can add.
Start with false.
Of course, we also want to have a float because sky cooldown counter.
Uh, counter will be equal to zero.
Okay.
And then we're trying to do here is if we are on cooldown already, we simply return because we're already
doing that.
If we're not on cooldown, we just start a coroutine.
And the coroutine will be called cooldown.
And then the cool down curtain, of course, will be another function.
Right.
I enumerator.
Quote down.
And here we just simply update the field amount of the cooldown while based on the cooldown counter.
Okay.
So here the first thing we do is based on cooldown will be equal to true now because we are now actually
on cooldown.
Right.
And you can see Starkwood will be called when the ability on start is called, which fulfills the condition.
Right.
We are actually on cooldown and if the ability will not start, it is not started, then this will never
be called.
So if we're here, we know that we are actually on cooldown.
Okay.
Now, we can also say that the coupon counter will be equal to the ability we're getting and then we'll
get the cooldown duration.
Now, of course, we don't have that function either, but that's easy to do as well because all we
have to do is to return, is to return the cooldown duration.
Which is a variable internally.
Right.
Now let's make another float.
I'm gonna call this guy.
Cooldown, duration, and we'll be equal to the cooldown counter there.
Okay.
Now, why do we need that?
Because we need to calculate a percentage which will pass in the fuel amount.
Right.
So we need to know the whole duration.
Right.
So while the cooldown counter is bigger than zero, which is constantly decrement it.
Cooldown.
Counter.
Cooldown.
Counter minus equals to the delta time.
Right.
And then we can say that the ability will or cooldown.
Well, actually cooldown well.
That fill fuel amount will be equal to the cooldown counter divided by the cooldown duration.
See, that's basically the amount we're looking for.
And then we just do a yield return new wait for a second, wait for in a frame.
We'll be fine.
Yeah.
And when this is all over, right, that means the cooldown is indeed finished and B is on.
Cooldown will be equal to false now.
And we also tell the cooldown well to just be disappeared.
So that's going to be as simple as enabled equals to false.
Right.
Okay.
And that should fire the coroutine and properly update the cooldown.
Okay.
All right.
I think that's actually it.
I think we're able to test it.
Now.
Let's go back here to the ability doc and just take a look at it one more time.
Uh, yeah, let's go back here.
And test it.
Now let me click on it seems like nothing's happening.
Are we moving faster?
No, we're not.
So something is off.
Let's take a look at it.
I'm going to go to the let's attach to unity, and I need to see some of the.
Adding some of.
Let's see if we if we're able to retrieve what's going on.
First thing to check is are we able to get the ability there?
Okay.
And then second thing is, what happens if we are there and we're trying to activate the ability what's
going to happen?
Right.
A few things we need to make sure that we're hitting.
Get used to that breakpoint method to debug.
It's very helpful because you can actually stop at that point and check all the variables, all the
data you're getting because those are going to be determining the the code.
So let me click again here.
You can see now we're here, right?
And let's go to the next.
And you can see we're indeed getting the ability to write, which is good, then we can continue.
And continue.
Continue.
I think we need to disable that breakpoint just to make it keep on going through the next.
Yeah.
Now I click it again.
You can see we're here.
The highlighted ability is the ability you right there and you can see the ability is speed boost.
Right?
We're good here.
So let's jump into the activate ability.
And now we're asking the ability to be activated.
So let's keep on jumping into it.
Okay now.
If commit ability, we can go there and take a look.
And keep on going.
Uh, so ability on cooldown is false, which is what's supposed to be happening.
If ability component equals no or ability component, try consume stamina and then return false.
Yeah.
I think the problem is indeed here because this should be in a not right.
Because if it is okay here, that means we are able to consume the stamina.
We shouldn't be returning false.
We should keep on going.
All right.
I think that's the issue.
So save that.
Go back here and then let's just try to run it one more time.
Okay.
Now let me click.
Then.
Oh, we're actually running faster.
That's good.
But I'm still not seeing the ability.
Well, I think I know why here.
Because we never set it to be activated when we start to cooldown.
So the good uncle routine in the ability.
Right before we do this, we also have to say that the cool down while that enabled equals to true right
before we do the rest of the things.
That's right.
Okay, let's give it another go.
Some expecting to see the circle rolling when we activate the ability and indeed it is rolling and you
can see now how we're running faster.
Right.
Another problem I think we're seeing here is that the it doesn't go slower.
Right.
So that is the problem that we need to look at.
Why are we not slowing down when it's finished?
So let's see.
Ability here.
The the the speed boost ability is here.
Right?
We're activating it.
We do all these add move speed startcoroutine reset.
Both duration and ad move speed.
So what's going on here?
Are we hitting that?
Okay, Let me just attach to you one more time and see the problem.
That's weird because we do have this reset speed when we are done.
So something is off.
Not sure what it is, but again, these kind of debugging is something you have to face like every day.
It's only natural to see it.
So I think it's good that we we go through these multiple times.
So let me click again there and then yeah, that's good.
Let me do a continue.
Okay, we're here.
I have a breakpoint here.
So the movespeed is 25 post amount 20.
Our initial speed is it is 25 now.
So continue.
Right now.
We're here.
Okay, so let's take a look.
The player and you can see the player's move speed somewhere if I can, you can also go to the to locals
and find.
Oh, we can't really see that for some reason.
Maybe the auto's here.
Okay, player.
And then maximum speed.
Uh, Adam, Speed is here.
Move!
Speed is 25, right.
Let me jump into the code.
Movespeed is currently 25 and we're managing 20.
Right.
So the move speed will be equal to five.
And we're clamping it.
So what happens if we clamp it?
It becomes 20.
Because our minimum speed is.
Something is wrong with the clamping step.
Let's take a look at that.
Okay, so minimum speed is five, but I think we changed it somewhere else to not five.
I'm not so sure.
Max speed is 80.
Move.
Speed starts with 20.
We need to look at those numbers.
Okay, so back here to our player.
And let's take a look.
The player class is in here.
Minimum speed is 20.
All right.
That's simply wrong.
Because if that's the case, then, yeah, we cannot go lower than 20.
I think it's five.
In there and the move speed is 20 for some reason.
That's so weird.
But let's just change that to.
Oh, actually, it's fine.
Move.
Speed is five, so me move.
Speed should be five instead of 20.
Yeah, that should be the reason why.
Yeah.
Okay, let's give it one more go.
And now let me cast the ability.
We're running faster.
But when that's finished, you can see now we're back to not running fast anymore.
So give us a like a two second super speed boost.
And you can see now we're able to see the ability being added in and cast it.
And we are able to also spot some bugs in our previous code.
But you can see now we are indeed successfully having one ability working and that's going to be the
end of this video.
Right?
In the next video, though, we're going to try to have some fun with the UI.
I'm going to actually add in add in some some animations to this UI to just to show you that we can
make it more interesting because one of the problems we're facing now is that if you are using the finger
to touch it, the ability you're touching is blocked by your finger so you don't know which one you're
touching.
Right?
It's actually a big problem.
So I want to make it to make this ability to pop out and become bigger when your finger is on it.
So that is going to give you a strong indication on which ability you're trying to cast.
All right.
So this is 20 minutes already, so I'm going to stop this right now.
And in the next video, right, we're going to add in some animation effect to the ability just to make
it much better to work with.
All right.
See you guys next time.