Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Rights of the enemies can hurt player but the player
Really hurt the enemy right it's not really fair system where we can hurt
The enemies
Alright so let's first just create a variable called health
Pretty anime
We have a private integer called health and by the fault it's going to be 100
And then we can have a private integer Max health
That's going to be 100 as well ok is very somewhere to a new player here
Can you play a has a
Health and also a Max health value
The same is true for enemies here
Ok
So what we're going to do here
Is Russia going to create something called
Hitbox
And hitbox is going to be
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
On a player you can also put them on enemies as well but in this case we're just going to put it on our player
And what is allows us to do
Is create an invisible field in front of the player
Hurt enemies if it touches those enemies
Usually you will activate this by clicking your mouse button or may be pressing I don't know x on you
Keyboard in activate that invisible field ok
What we're going to do is Russia going to create something called
An attack fox some people will call it a hitbox some people might even colder hurtbox and
I like that word because it implies that maybe the players getting hurt as opposed to the player hurting an enemy
Play Like a word attack box I think that's a really specific word
How to spell understand what is saying actually does ok
So I'm going to do is just a simple box Collider 2D
And we're just going to say is Trigger is true
Now I'm going to do is
Simply
Dragging over here to about 1 position of 1
Maybe we should put it right snow against the player that looks good so maybe .8 instead
Ok
We have this attack box
So the idea is that
When I press a key on the keyboard so the attack key or right click the mouse this will appear
Inherit the enemies that touch this box
So this could be swinging a sword or punching in this attack box is invisible
The way for us to you have an idea of where the enemy has to be to get hurt when they're in front of the player
So just be clear let's go ahead and just add a Sprite renderer of this
I can really see what's going on and
Looks like we don't have a square Sprite so just going to level one here and I just create
Google Pixel that we can use
Actually like to have
A single spray called white pixel in my games so that I can use it wherever I need to
To use that white pixel
On our attack box
What's an import here there we go
Dragon in there
Now we have a box Collider that's way bigger than my pixel so what happens is you can actually remove the box Collider
Inad again
And it's going to be now decide about pixel and then we could use the right tool
Just scale it up pretty big here
What's the job done here we go hold shift scale down to see her
Right here and let's make it red
So we get an idea what is actual attackbox is ok
Alright so
What's Tesla sell last thing you want to do is just make sure to trigger
Now it's tested out
Ok
So obviously I can't do anything when I touch the enemy but the idea for this box Collider
Is that one
We need to have it actually flip so when the players going left
Is a turn that's one thing we need to do
And also we wanted to be by default deactivated
When we press the attack key or maybe click the mouse
Quickly flash
My cat
Not obviously won't actually show that Red Box
For the purposes of creating this game right now you're going to show the box
When we click the mouse or press the attack
The first and foremost let's go ahead in make the player flip
When he's going in a certain Direction
What's the weather going to do that is simply go into the update
Create a new condition
Reddit comment here that says flip the players
Local scale
The xx
GIF
The move speed
Is greater than
Say 0.01 or West End negative 2.01 ok
Sophie's
Moving to the right
Is new speed is greater than 1 there for
Is
Logo scale should be positive
Otherwise it should be negative ok
Tell displayways to do this and is also really smart genius ways of doing this out of friend's name the araki actually
My game never song and he could probably condense down what I'm about to write into one line of code
But because we're all going to treat this tutorial as a layman's tutorial
Pretty rudimentary about how we write it's ok
If
Target velocity
That
X is smaller than -1
We're just going to set the transformed at local scale
2
New vector2
Where did you -1
And we'll keep why the same
You do lcf
Target velocity
Directions greater than 101
Just putting back
21
Ok
To this should flip the players local scale
If he's moving to left or is moving to the right
Stridor sound
Tiplee
Awesome
Just for clarification guys
It has the attack box
Is a child of the player
When we flip the -1
The attack box is going to do that as well
All I said when we click on the attack box there is a scale is still the same here
But it's being influenced
Buy essentially a multiplier
On the parrot
Which is -1
Even though it's scale is 10 essentially 10
Because the players x scale is -1
It flips the child inside of it think of nesting dolls that are really good way of thinking about if you turn a parrot nesting
Around may be flooded upside down
What's inside of it is locally basically the same but globally
Based on the parents rotation
Drogheda rotating side
Alright there we go
Alright so he flips now so now we get erase and code
Dad will
Make the box appear only
When we attack and I actually really like attack to be a mouse click you guys can make it worse
Why if you want to be the X key or whatever that's totally fine so first off the very first thing you need to do is go
Project settings
Emily go to work input manager remember this and we go to
Fire 1
Fire one is ok it's the positive line is left control or
Ok so it looks like we can use the input
Stream name of Fire 1
Actually make this thing appear
So let's try and do that really quick
Let's do some pseudocode here if
We press
Fire 1
Then
Set
The attackbox
To active
Otherwise
Set active to fos
Ok I will do this wireless give it a shot must you
Input
Diet
Get
Button
Down
Fire 1
Then we need to say attack box set active
True
We have a little zig zag haircuts this variable doesn't exist so that variable appear
Betsy here I think putting it somewhere around here is fine will organise over variables in a cleaner
Section of a tutorial but for now we're just gonna put the right here and let's go how to make a private but we do want it cereal
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
Serializefield
Private
Silly a game object
Check tax
Go back in the unity here
And now
We have the attack box showing up here but there is no reference to it to Unity doesn't really know
The gameobject is supposed to be all in those that it is a gameobject unity
Is this
If you go back into the scripture
If input.get letting down fire 1
Will make the attack box
Activate
Not obviously guys there's cleaner ways of reading this code we can compress this down into one line
But again for the purposes of this tutorial I want to make sure everything is as clear as day to you guys especially with
Conditions
It's a bit out here going unity
Hopefully when we play here this looking really deactivate because when I actually pressing the mouse
Click it
Quickly appears
Now you'll notice that it's really fast I mean sometimes you can't even see it it'll disappear immediately
Well we need to actually write a function
See the active for a set amount of seconds ok
Because clicking a mouse
Is so fast
Times you can barely even see the attack box and I can imagine that would be very third of a player because who knows
Maybe that attack box doesn't last long enough
Even hurt the enemy
So instead of having it immediately disappear in a scripture
What can I use as something called a coroutine
And I know what you're thinking that's a really weird word what the heck are we talking about Thomas and
I'd ever later saying hey guys feel I really do because I don't even know if I'm saying it right it doesn't matter with me
I know what it's use is right so take a look at what a cuppa routine is
Inside of Unity
It says the execution of a current team can be passed at any point using the yield stable
When a years statements used the curry team passes execution in America
Resume that the next frame business what the heck are they talking about basically all occurrence
Is guys is it allows us
To start a function
And that function can actually pause for a certain amount of seconds
And then continue
So why is this valuable to us
Easter Mouse is clicked
I want to start a function called what's a show a tack box
I want to wait maybe half a second
And then disable the attack box
So let's go ahead in create that so let's just write out some pseudocode here but
Start routine
Activate attack
Ok
That's going to be r function so we're starting a curry teen and it's called
Activate attack
Now let's just put it right below here just so we can see it this is going to be activate attack
Punching ok that's just a comment for me to know what this is
Create a function the status in tax year is public void
Activate
Tag
And then we're going to activate the attack box so attack box set active true
Then we're going to wait point
5 seconds
And then we're going to send it back
Boss
Licence
How we actually write this code out to go back to the unity documentation
You can see here we can use this command here
Yield return new waitforseconds is just basically a way of saying a unity I need to wait
Stop reading stop your speed reading and just wait
Return new wife for s a m 2.5 s
So we're getting this red zigzag here what is that mean well
Guys don't rush things right always look at your documentation what's exactly 2
Wrong is well we didn't read the documentation in the documentation it says this is actually how
We declare
A function that uses
Await time
It's cold
In saying that right I'm leaving now but I'm getting it doesn't matter what matters is
You know what these things are used for ok and then you can do
You know Google and unity documentation
So when using a function that waits and stops reading for just a second
You going to make it a type of a numerator ok
Cell
Instead of void
What we're going to write is
Ienumerator there is not a memorable but I numerator
I don't even know what that means
Ok well I know that we can now use this way time
Tell
I'm coming to sell start coroutine
Activate attack so when we press fire
It's going to start a career team meeting is going to start a function that uses
Away time
And that's called activate attack
And here's the function
It looks a little bit different than a regular function because it is use void actually utilising in ienumerator mean
We can now wait so this is one of those things in unity guys where I still to this day
Will have to Google how exactly to write this stuff
Just know
When you want to put a wait time in your function and have a wade
Username generator
Mm to actually call this function you need to make sure you type start a routine before you actually call
Stop the function ok
That doesn't make sense it's ok we can use these a couple times in a game
Tell this is the only time we're going to use it so don't panic
Don't make sense the more you use it
What before we hit playlist just make sure attackbox is deactivated by default
To play
And what should happen as when we click
Unity should literally stop
Reading the code it's just wait
In that function is Gonna Go hold on I'm gonna wait as like Thomas told me to
And then deactivate the attackbox cyclic
Activate wait deactivate
Activate wait deactivate
That allows us to have
Some kind of control
Over the length of the Punch
Set a little bit too long isn't it so we could do is actually just
We can do it this way .1 f
Or another way of doing it is
Attack decoration
Yep
Exist there is the exact line that's ok
Now we can
Free specific year 8 serializefield private float attack
Direction
Now we can go into unity in actually tweek the attack duration at runtime
To get to feeling perfect right now I think
500 start with Dad
Play here that's a little too long isn't it
What's make it 1
Have you got a fair
I'm at a time
To activate that attack box for the player
So now I need to write a script
That will check to see if the attack box is hitting anything
We could technically put this script
Anyway really we can put it inside of the player we can also put it inside of the enemy script as well
But I'm actually couldn't create a new script called a tack box
Because honestly we can use this script
Across various game objects not just for the player
Are you guys or Cy in future videos
For now I guess I just asked you to trust me and we can create a new attack box script
My guys are getting weird warnings weird errors
Affecting your game that's part of the course of Unity outlets drag the attack box here
Now we have the attack back script
On her attackbox game object
Because this is a Trigger
We can actually diffuse the on trigger function
Witches Google there
Unity on trigger enter 2D
Let's see
Where are you there is
Happiness
Pasted into a script again guys
Writing code is it necessarily writing code
Actually physically typing it right sometimes has just researching it finding it and using it
So this case we're just going to use this right here void ontriggerenter2d
And I will do as soon as cold here
Yes I touch
An enemy
The enemy
Ok
Sort this out if
The collider2d which is called col col
Game object
Let's see how can we identify if it's an enemy what would you actually do game object that name =
Anime do it that way
I touched an enemy
Ok
Does say they're out for now and just see if that works
Ok
It's like this year
His name is anime
Closest
Play and see what happens
Ready
I touched an enemy
Looks like it's doing it pretty buggy pretty good to you right now but that's ok we're gonna clean that later
So that works great but honestly not every enemies name is going to be enemy right
So what if we did something like
He said if
Col call gameobject get component
Anime
Collider 2D has a component called enemy
Then
Do this debug reason why we do that is because if inside of you nearly here
My copy and paste and put another Enemy here
You need is going to add a printer says one here
By default
And that means that it would no longer be able to check
Using old method if the name is actually anime
But because it has enemy class
That's a great way to check if you're actually hitting in enemy
Turn it down
Attached an enemy
That's great
Ego
Alright
So that's working great so all we're going to do here is simply just go
Call gameobject
Getcomponent
Enemy
Health
- equals
1
Why is this health got a red zigzag and I need it what's going on
Well remember we got your enemy we can look at our health is actually private
This is an instance where we actually want to make it public otherwise we'll never be able to change
Then
The last thing we want to do is just in the update
Are we going to do is good condition
Something like if health is smaller than 0
Destroy Me
The way we write that is if
My health
Is smaller than 0
Destroy
Game object
Obviously guys there's two ways of doing this you can actually destroy a gameobject
What you can just do gameobject set active
But I'm ok with destroying
Something that you should know that is destroying a game object or cos he very slight
Slight drop in frame rate
In your game
But if you're doing it
Not that often saucy work killing an enemy every 30 seconds it's not that bad song in half
Destroy function just completely destroy
This game object from the game
I see here just delete this enemy here we don't need this
And it's only focus on this enemy right here
Let's watch it health
As we take it
Get down a 99
Ego
So we definitely don't want
Only go down by one unit at a time
And I want this game feeling like more went when you first start out I want you to be able to kill an enemy in maybe
It's ok
So if 100 is going to be the max health across the board for enemies and the player
Then I say we want to decrease by 4 hit so
Value of 25 + decreased by a value of 25
So
Attack power on the enemy here
What actually happened attack power on the new player as well
Then we can subtract that attack power
From the Enemy
Public editor
Attack power
What's my day
25
Now when the attackbox hits in enemy
Simply Go
Decrease by new player that instance
Now we can have some kind of RPG elements in this game
We can actually increase the attack power maybe take a purchase increase in attack power maybe every time that beat
Herbal beginning increase in attack power
Tell if we go to iPlayer here
Protect H 25
I mean it's going to take
4 hits
How to kill the enemy
1
2
34
His health is currently 0 so it actually going to take 5 hits
Easily just jump into your enemy here
Change this to if health is smaller than or equal to 0
Destroy gameobject
No you guys me have noticed that
The attackbox is actually causing the playlist stock rate
Stuck in various places
That's because when a Collider
Even though it's a Trigger
Is a child of another Collider
In this case
Is the child of this capsule Collider here
Double click here in June in this attack box
Is actually because this capsulitis here
It's been treated as another
Collider
You know it's still said to trigger is it just a weird idiosyncrasy with unity they're not gonna get too much detail about
By the way that we fix this is just simply add a rigidbody 2D to it
And then we're going to make that kinematic and all kinematic means is
Exactly influenced by Gravity it's not good actually fall or move like a rigid body would
Just going to be stable so I can remove it all
And also that use for kinematic contact
Is quite
A little bit of a weird
Problem
Are you going to have but just had a rigid body
Gearbox Coletta new speaker
Tested out now
Get stuck to things
But I'm still going to get that triggering
And I can kill you
Are hydrate beautiful her just a beautiful too
I'm up games
Not yet that's ok though how are doing is getting the basics down
To the concert skinning it later
I want to do guys make sure you guys get this number right you just want to set the attack direction to something that
Like so I would say .05 it's great for me
A really quick Direction
There we go that's perfect
I know right perfect now there's plenty of things here guys that we could fix right
We need to add a type of feedback to the player meaning if we get hurt we need to flash the screen if we
Hurting enemy we need a flash that enemy
Things that we need to do and we can talk about that in future videos
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.