If we click left mouse button then we will play attack animation clip.
So basically what we need to do if we move over to animator tab and select this player in the hierarchy,
we need to trigger this attack one, attack two, and attack three parameter through our code.
Once we gonna click left mouse button.
So let's open up our player script by double clicking on it.
And let's do it.
So we're gonna do it inside update function.
For that we will make a separate function as well.
So let's check it over here.
So let's use this if condition.
Let's make first bracket and some curly brackets.
And what we want to check over here.
We're going to check for some input.
So we will use this input dot get get get mouse button down.
And we need to make this brackets.
And inside these brackets if you pass one it basically means that you just clicking the right mouse
button.
Since we're checking for left mouse button.
So that's why instead of one I'm going to pass zero.
If input dot get mouse button down basically means that we just clicking the left mouse button.
So what we're going to do we're going to trigger that parameter which is attack one and attack two like
that.
So let's make a function for play attack animation.
So let's make it over here.
So for function we're going to type void.
And we're going to call this function to something like play attack attack animation.
So let's call it and let's make first bracket and some curly bracket.
So what we want to do inside this function basically we need to trigger this attack one, attack two
and attack three.
So let's suppose we want to play the attack three animation clip a animation clip.
So basically we need to trigger this attack three parameter.
So firstly we need to move over to this animator component.
And we need to use this set trigger function.
Because this is a trigger and we have to pass the parameter parameter name, which in our case attack
three.
So let's do it.
So what we will do.
Firstly we will move over to animator component.
And now we're going to use dot set trigger function and then make this first bracket.
Why are we using this trigger function instead of set float.
Set bool because that attack three parameter or attack one attack two is trigger parameter.
So that's why we need to use this set trigger function.
And inside this brackets it's going to take the name of the parameter in quotation.
So I want to play the attack three animation clip.
So we need to trigger this attack three parameter and make sure you spelling it correct and close that
off with semicolon.
So whenever we're going to click the left mouse button then I'm going to call this play attack animation.
And what this function just going to do.
It's going to move over to our animator component.
And then it's going to trigger this attack three.
And we do note that once we trigger it at a three, it's going to play the attack three animation clip
as we saw earlier.
And now, uh, we we have to call this function.
So let's call it over here.
So once we're going to click left mouse button then we will call this play attack sorry play attack
attack animation.
And let's close that up.
Close that up with semicolon.
Make first bracket and then close that up with semicolon.
And let's press down Ctrl S to save our script.
And now let's move over to unity.
So as soon as we're going to click left mouse button that play attack animation function just gonna
trigger or we simply calling it.
And what that function is really doing is just going over to animator component.
And then we're using the set trigger function in order to trigger that attack three parameter.
And we do know that if we trigger this attack three parameter, it's gonna play the attack three animation
clip right away since we just triggering that attack three parameter.
So just wait a little moment and you will see.
So just wait a little moment and once our compilation is done, we can just go ahead and then we can
play our game.
And also if we click the left mouse button then we just triggering that attack three parameter.
So now the compilation is done.
So let's click on this play button in the top in order to play our game.
And let's try to click left mouse button.
So as soon as we're gonna click left mouse button that play attack animation function just gonna call
and that function just triggering this attack three parameter.
So if I click left mouse button, as you can see, as soon as we click we can see that we playing attack
three animation clip.
But the problem is that I want to play this attack one and attack two animation as well.
So we also need to trigger this parameter.
So I'm gonna choose a trigger.
Basically I will trigger a random one like this.
Attack one, attack two, or this attack three.
So if we just trigger a random attack, uh, basically this parameter, uh, by picking up a random
one, then it's going to do so instead of playing a some certain parameter.
Basically, instead of playing this attack three animation clip, we're going to choose a, we're gonna
trigger a, we're gonna trigger a random attack one random this attack one, attack two, or attack
three, a random one.
So it's gonna play the random animation clip, which can be attack one, animation clip, attack two,
and attack three.
So let's get out of play mode.
And for that, we're gonna use, uh, a random dot range function.
So move over to your scale.
So before we instead of playing a some certain which in our case attack three, we're gonna choose a
random one.
And then we're gonna play that animation clip.
Basically we need to trigger that attack one, attack two, or attack three, basically a random one.
So it's gonna play, uh, those animation clip which can be attack one, attack two, and attack three.
Animation clip.
For that, we're gonna use this random random dot range function.
And we do know that this random dot range function in brackets is going to take the minimum inclusive.
So we will pass zero and it's going to take the maximum include maximum inclusive.
Sorry.
We we're gonna pass uh three uh three.
And let's close that up with semicolon.
So this random dot range function, it's gonna pick up a random number between 0 and 3.
It can be zero.
It can be one.
It can be two.
But it's not going to pick up this three.
It's gonna accept that and it's gonna pick up zero definitely.
So it can be random one.
It can be zero.
It can be two and it can be one.
So what we're gonna do whatever this random dot range function pick up, we're gonna store it into a
int variable.
So let's store it and let's call it attack index.
So let's call it attack index.
And let's set equal to this.
So let's suppose this random dot range function pick up one.
So this attack index right over here it's gonna be one say because we directly setting it as you can
see.
So in that moment what we're gonna do, uh, we're gonna play a we basically we will check.
So we're gonna use this if condition.
Let's make first bracket and some curly bracket.
And let's suppose this attack index became zero.
So if our attack index is equals equals to zero, then we will play the first animation clip.
Else if else if our attack index attack is index.
If it's equals equals to one then we're gonna play the attack to animation clip.
Else if it's not 0 or 1.
And let's suppose this a random dot range function pick up two.
So in that moment we're gonna play the third animation clip.
So else else we will play the third animation clip.
For now, let's print out a message.
So if our attack index is zero and we do know that this random dot range function right over here is
going to pick up a number between 0 and 3.
So let's suppose this random dot range function pick up one.
So it's going to move over to this if condition first.
So attack index is one.
So this right over here just going to be false.
Because attack index is not equals equals to zero.
So it will move over to next.
Else if condition.
So attack index right over here.
As you can see we assume it one.
So this condition right over here becomes true attack index is equals equals to one.
So in that moment we want to play the second animation clip.
For now let's print out a message.
So if our attack index is zero then we're going to play the first animation clip.
So let's print out something like Debug.log.
Uh play play attack one animation clip, Something like that.
Attack1 animation animation clip.
And let's close that up with semicolon.
And we're going to copy this line of code by Ctrl C and sorry Ctrl C and let's paste it inside over
here by Ctrl V.
So if our attack index is one then we're going to play our second animation clip.
So I will say something like play attack to animation clip.
Else if our attack index is not equal to 1 or 0, if our attack index is something like two, then in
that moment we're going to play the third animation clip.
So I will say something like play attack three animation clip.
So now let's press down Ctrl S to save our script.
And now let's move over to unity.
So if our attack index is zero then you will see in our console tab the first animation.
The message says like play attack one animation clip just gonna pop up.
up.
But if our attack index is one, then it's gonna say something like play attack one.
Animation clip.
Sorry.
Attack two animation clip.
Else our if our attack index is not is equal to zero or 0 or 1.
Let's suppose this attack index is two.
Then in this situation, this third uh third else condition this right over here just gonna be execute.
So this message should be pop up.
So let's move over to unity and let's select our console tab.
And let's click on this play button.
So as soon as we're gonna click left mouse button we're gonna see a random message just gonna pop up
in our console tab a console tab.
Because since this random dot range function right over here gonna pick up a random number between 0
and 3, it can be zero, one, and two, but it's not gonna be three.
So if I click left mouse button, as you can see play attack one animation clip.
And now if we go ahead and click the left mouse button one more time, we can see a play attack one.
And now it says Play Attack three, animation clip attack three, attack one and attack three.
Uh, so let's, uh, click some more time.
I don't know, it's, uh, only picking up, uh, zero.
So it's not doing so it, it can be one, two and three.
So as you can see if our attack index is zero.
So in this situation what we're doing we just printing out play attack one animation clip as you can
see.
So this random dot range function just picking up zero.
And over here it just moving over to the first if condition.
So if our attack index is equals equals to zero.
And let's suppose this random dot range function pick up zero.
So this attack index will be zero.
So zero is equals equals to zero.
So that's why this uh message just getting pop up in and pop up in our console tab says Play Attack
one animation clip.
As you can see.
But if it's something else, basically if our attack index is one, then in that moment we are printing
out this message, as you can see, which says play attack to animation clip.
And if our attack index is two, uh, is not equals equals to zero or equals equals to one.
Then in that moment, as you can see we printing out this message says play attack three animation clip.
So instead of printing out a random message we basically want to play a random animation clip of attacks.
So if I move over to my animator tab.
So basically we need to trigger a attack one as well as attack two and attack three.
Uh, if our attack index is zero, then we're gonna trigger the first parameter.
So in our case, attack one parameter.
And if our attack index is something like one, then we're gonna trigger this attack two parameter.
And if our attack index is is two, then we're going to trigger this attack three.
Sorry attack three parameter instead of printing out message.
So it's going to play the random animation clip.
So if I go ahead and manually trigger this attack one, attack two and attack three animation clip.
As you can see it just playing, uh, the attack one, attack two and attack three animation clip.
So instead of doing manually, we're going to do it through, uh, through our code.
So instead of printing out message we're gonna trigger those parameter.
So let's get out of play mode and let's double click on this message in order to open that up.
So if our attack index is zero then I want to play the first attack one animation clip.
So what we will do we will go over to animator.
And then we're going to use this set trigger function and make this first bracket.
And inside this uh brackets in quotation it's going to take the parameter name.
So if our attack index is equals equals to zero, then I want to play the first animation clip.
So in my case I need to trigger this attack one parameter.
And now let's close that up with semicolon.
And I'm gonna copy this line of code by Ctrl C.
And let's paste inside right over here.
If our attack index is equals equals to one then I want to play the second animation clip.
So in my case I need to trigger the second parameter which in our case attack two.
And we're gonna replace if our attack index is not equals equals to one or equals equals to zero.
If our attack index two uh attack index is two.
So in that moment I want to play the third animation clip so we can simply, uh, cut this and let's
paste inside right over here by Ctrl V, Ctrl X for cut and ctrl V for paste.
So if our attack index is not equals equals to zero or equals equals to one.
And if our attack index is two, then what we're doing, we're just going over to.
Animator and then triggering the third parameter.
And if our attack index is one one then we're just triggering the attack to.
Parameter.
And if our attack index is zero then we just triggering the first parameter, as you can see.
But we do know that this random dot range function is just gonna pick up a random number.
It's not gonna pick up all the time zero or 1 or 2.
It's gonna pick a random.
So basically we're gonna able to see a random animation clip just gonna play, since we're doing, uh,
using this random dot range function.
And this attack index can be a random one, it can be zero, 1 or 2.
Uh, if if it's two, then it's gonna play the third animation clip.
If it's zero, then it's gonna play the first animation clip right over here, as you can see.
And if our attack index is one in that moment, it's gonna play the second animation clip since we triggering
the second parameter.
As you can see.
Firstly we going over to animator component and we using this trigger function in order to trigger that
parameter and make sure you inside this quotation, you pass the parameter name perfectly and make sure
you spell it correct.
And once you are done, press down Ctrl S in order to save your script and then move over to unity.
So we should able to see a random attack animation.
Just gonna play.
It can be first, one, second and the third since that random dot range function.
Just gonna pick up a random number between 0 and 3.
It's not going to pick up three, but it's going to pick up two, 1 or 0.
But it can be random one.
So we will able to notice a random attack animation just gonna play.
So let's click on this play button in the top in order to start our game.
And let's try to click left mouse button.
Then we're calling the play attack animation function.
And that function basically picking up a random number and then triggering a random attack parameter.
As you can see, we are able to notice we playing random attack animation clip, we playing the third
one, we playing the first one, and also oh, also we playing the third one and the second one.
So this is the third one.
This is the second one and this is the first one as you can see.
And we can take a look in animator tab as well.
So if we select our animator tab and then select the player game object in the hierarchy, we can take
a look in animator tab.
It's triggering this month.
This one and this one I guess.
Yes this one.
So it's triggering a random one.
So I hope you get the idea.
And you can notice in left side in animator tab as well.
So I hope you get the idea that how you can do it.
And let me explain one more time.
So I'm gonna get out of play mode.
So firstly, what are we doing if we move over to script?
Uh, firstly we checking if we, if input dot get mouse button down zero basically means that if we're
clicking the left mouse button, then we're calling this play attack animation function.
And that function basically doing these things.
Firstly we are using this random dot range function.
Uh and we pass zero and three since we have three animation clips.
So that's why we pass as a second argument three.
So this random dot range function just going to pick up a random number between 0 and 3.
It can be one, it can be two and it can be zero.
So let's suppose this random dot range function pick up uh one.
So this attack then what we're doing we're storing that number into this attack index.
So this attack index is just going to be one.
So it will move over to first condition.
And it will check if our attack index is equals equals to zero.
So we assume it one.
So this if condition getting false because attack index is not equals equals to zero.
So it will move over to next.
Else if condition.
So now it's gonna check if our attack index is equals equals to one.
And we assume it attack index is one.
So this condition over here getting true.
So in that moment what we're doing we're just going over to animator.
And we're just triggering the second parameter which is attack two.
So that's why it's playing the second animation clip.
So I hope you get the idea.
So you can use this random dot range function in order to pick up a random number.
And with that random number you can simply play a random attack animation clip.
So I hope you get the idea that how you can do it, and make sure you press down Ctrl s on your script
in order to save your script, and then move over to unity, and also press Ctrl S on your keyboard
in order to save your project.
So whatever you have done so far in Unity Editor, it will be saved.
And we can just go over to console tab.
If we have some messages, we can just clear that as well.