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
Alright guys now we're to talk about one of my favourite things to add the
And that is the enemies
Search make a double platform here for an enemy to be able to walk on so maybe take this platform
A nice little platform here and working at create
An enemy
The first thing we're going to do here is just go to our level 1 PSB
Double click on that in let's just go ahead and create an enemy graphic
Create a new layer here and its name this enemy
And let's see hear about that use the rounded rectangle tool
Maybe let's see here about 1000 pixel radius so it's really round so maybe
Like this
Just make it white for now
With no stroke
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
And what we can do is actually rasterize the shape currently is a vector ok a vector is
Basically a math equation that creates your shape that's not actually pixel data it's more of a massacre
So we can shift all of these shapes
You make it look different traits
Set a raster image Adobe Illustrator is for
Photoshop is raster graphics better than the future before now we're going to right click on the landing rasterize layer
And then we're going to use the rectangle selection tool
It's little rounded bottom off
Something like this ok that's our enemy
What's about this PSB file
Jump back in the Unity
And it should show up right here
You are
Duchess going drag it by here
MSP Shirley put this inside of layer
Where is it one here
Get
And also this guy also need to be on later one as well
Just clean that
Ok so we have our enemy here
What's a changes colour to be a little bit more threatening right baby
When I'm full-time Game Dev pink
There we go
Ok so
What the heck do we do now
Is actually going to be a lot like the player
Player moves
Whether rigidbody in a capsule Collider in remember if we open up the new player script
It extends
2D physics object script
So I think we can do the same
With their enemy
Script
The first we need to actually just add
A capsule Collider
2D not the regular one but the 2D version
That's going to ignore the z-axis
Every double click on the enemy we consume a little bit there
Collapsed this down here and you can see there's a small green circle there
That's great actually nothing you just said it all remember guys we use a capsule Collider
So I can smoothly climb up hills it doesn't get stuck on angles
If it was a box Collider
Judy
Just like in real life if you imagine pushing a box up a hill it might start to Tumble in tip
Because there's friction right here at the corner is getting car
So we wanted to be
Capsule Collider
There we go
Don't forget guys
We also need to add a rigidbody 2D
Collider
Actually collides and stops the object from falling through things
Original body makes it fall right it makes it an actual physics object that engages
With gravity
We can also be sure to change the constraints so that we can rotate in the Z axis
We don't want to talk the other
All over like this right
The final thing we need to do here is just remember that the player had a collision detection
Set a continuous just going to make it a little bit more effective
At colliding with the ground
We're not ever really wanted to go to sleep
What's the inequality in a polite and these are necessarily required but these things are actually
Allow the enemy to be very precise in its movement
Ok
Now the next step is just to create
An enemy script
Search click the plus I can hear c-sharp script
Can I call this enemy
And again guys I can't say this enough if you get errors and warnings and stuff
The game is working don't worry about him I'm definitely gonna do a sort of spring cleaning episode where are we
All of these aleros in Stafford trying to figure out why they showing up in that really cares there more like warnings
So another worry about it for now I'm really jumped individual studio in start programming or enemy
And you noticed that even as the default template
40 subscript
Do you know that extending to the monitor behaviour
What is remember the new player actually extends to the physics object in a script
Houses to have very precise movement
That's very you need to players in enemies not necessarily a standard physics object in unity
So we have this custom physics object script
To that
My enemy as well
Because we have very similar movement to what the player is
It's going to extend
To a physics object
That means we can actually just really quickly test here
Remember a new player if we scroll down here
We can set the target velocity
To the horizontal into it
So we can use a similar type
Statement
In the enemy so let's make it move to the right
Target
Velocity
Equals
New vector2
SD Wan
And then
0 in the Y Direction is fine
Alright so that should hopefully
Get enemy to stop moving
To the right
So let's move our player
Over here so we can actually see what happens
The moment we hit play
Nothing is happening
Priory figured it out in you
Ensure that every time you create your scripts guys
You add your script
2
Prefab
And don't forget to create a new prefab
The enemy
Ok now things should work at hip play
Egos
See how he behaves
Any falls off
Buildings behaving exactly how we won into that's awesome
So what if I wanted this enemy
To move
La more I guess unique speed when I want to specify
In the actual inspector over here
What are we going to do is just like the player
Create a serialised field I know it's going to be private
And it's going to be a float value in a going to be max speed
Now we can just make this
Max speed
And go back into unity
And now we can set your max speed to something like an O2 maybe
Hipley
Ok very good
Moves at a speed of 2 perfect
One of the most
Basic in rudimentary forms of enemy types in enemy movement
Humanity is a patrolling enemy type
So you're not in play mode here basically if you do something like this it's just
Look for a legit seas one it's going to reverse course
That's basically all our enemy is going to do
Now we can definitely have a variable that says well I don't want you to avoid I just don't want you to fall
So sometimes they could just fall off a ledge
So maybe we can have two enemy types one that patrols and one that doesn't roll and just falls off ledges
Also we won at 2 if it would say it's over here
If it hits this while we wanted to reverse and get stuck
How on Earth do we do that
Well what are you something called
Raycasts
This might sound really complicated it's really nice it's not scary it sounds I know that when I first learnt about rape
I really got scared and you guys don't need to be scared I'm going to work through it with you and hold your hand
It's not that bad basically recast or these imaginary lasers
Shoot from various locations of your player
And we can choose where it shoots from what's the angle that issued from and that laser is that right
Touches something else
Then we can do something so it needs a condition and then we do something
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
So in games the way that players can maybe see if they're at allege is they have a little
Cast that happening right here
Actually I can just draw it out for you with a shape year so let's take this shape
Unless draw out an imaginary raycast
To show you cannot what it's not look like
This re cast
You not going to be able to see it
It's going to shoot out
About right here
And you could specify it's like right
So if it shooting out at this length
And it doesn't hear anything
It's going to inform the enemy class the enemy script hey
There's a lead here I need to be careful
But if it's over here
Hitting the ground
Hey hey I'm not in your allege I'm going to go and keep moving ok
It's really not that complicated in script something to show you how to do that
Right now so really delete the ground
And we're going to the enemy here
In the jump into the enemy script
Git create
To raycast variables ok
Create a private raycast hit
2D
And this is going to check for the right lead
What's going to be called right ledge raycast
Let's go ahead and another one private raycast hit 2D left
Raycast
Lowercase the c here
Raycast hit you want to match the variable type here
Ok
So now we have a right ledge raycast hit and it left ledgeway cast variable
Say that's tripped out and it's not really going to do anything right now just declaring these
Cast hit 2DS into existence but they don't actually do anything right now
So in a way I think this is we just created these little laser in metres these raycast e m
And we can now use them almost like Caroline guns almost you going to shoot these rain
Ask the various directions in check and see if we're hitting things right
The here we go
So let's write some pseudocode here
Yes
The
Right ledge
Raycast
Hit
Fires a laser that's called a laser and hits ground in front of the player
On a rate
We are not near a ledge
Taxi breakers in the two lines here
Would you do that by just doing this
Alright so this is our pseudocode here
So the first thing you need to do is tell the raycast
What to do where do what's the direction
What's rated out like this
Equals
Physics
2D raycast and thinking how to write this and looking at unity document
Switching on my other monitor and you guys should too
New
Electrocute
And let's see here what is this mean well or telling the raycast
Where to omit from
Where we shooting it from
Well we wanted to admit from the position of the enemy right
So we got to do is type transformed at position x
Karma
Transform
Positioned at why
UK
What else is going on zoom and a little bit
Looks like we have
Female prime minister film
The next one
So if you type comma the next one right here it tells you in a little call out
But now we need to specify the direction
A very quick way of writing the direction is vector to down
In all down really is 0 and -1
Settle down really is
Vector down
Picture to down comma
And now we're going to do the actual distance or the size of the red cast
What's 2
24 now
And that's about all we want to do for now
So literally all we just did was we told the right lead raycast hit
What direction what size where is going to go
And then now that we've told it what to do
We can check and see
Hit anything
Now
I guess I can go in the unity and hit play
Answer guys I can't see anything
Can do that
If you go into unity
And it play
You can't see anything nothing is happening right
Because we've told the raycast to shooting a certain Direction
It does actually show up and there's no conditions being met anyway it's not checking to see if you're hitting anything
Are telling the radius what to do is to shoot in a certain Direction at a certain position
So now we want to do is ladybug
The Ray do you get some other debug.log that log I'm shooting
Is also debug draw Ray
Escape draw a raycast ok
So where about to do is a little bit redundant to be honest I I cannot wish and unity had a quicker way of doing this
This is about the only way that we can do this ok so we're going to remove this log that was just
Debug in organ he was basically right out what we brought out here
So debug
New vector2
Transform position x
Transformed at position
Karma
The Direction now the thing is
Is that
Raycast parameters appear or different than the drawer parameters
The drawer primers instead of a comma and then to you actually just go x x 2
It's really weird honestly the raycast scripts
Horsey Sharp and unity or little bit another word
Confusing but it's ok guys again making games in 10-years I still have to reference the doctor
Patient to make sure I know what I'm doing here
And that's ok
Alright so we're going to go down
We can also specify the colour
Colour.is blue
Ok
Today's should draw a ray
Down in the sizes going to be too
Alright would say that out in jumping unity and see if we can see this re being drawn
Now before we actually have playlist just said our enemies movement to about point
Just so it's moving a little bit slower so we can see it
NIC play
Where is ra
It's being drawn from the centre that transform deposition at x
Transformed application that why
Back tattoos down going down in the direction of down
Is it a size or length
A 2 units
That's perfect
So this is going to check and see if it's basically a laser
It's going to check and see if you're hitting the ground
Currently we don't have any conditions will have an if statement to check and see if we actually touching anything right now all week
Is a raycast being shot towards the ground
Always below the enemy
It's also been debunked it's been drawn to the same view
Now you may wonder how is this going to detect if there's a Ledge to my right
Well are we going to do is go to a script here
I'm actually just shift it to the right a little bit
No not necessarily at the exact exposition centre
To the enemy but let's do Plus
1
Anytime you make an adjustment
When you're casting your Ray
You also make the Adjustment when you're drawing it as well again pretty returned it I cannot lie
About the only solution I've ever found so let's go ahead in
Play
Embassy now
Laser it's almost like a camera on a car something
That can detect
Where
The enemy
Is init a close to a lead tray
I can warn the enemy and tell them to reverse course
So let's make this point to
And you can see now that as it approaches the ledge we can actually check and see if it's touching anything I'm not
Anything reverse course and change its direction in move in the other way ok
So keen on little more control
4anime here well
Having one here
What's maybe have a variable called raycast offset
X
That doesn't exist right we need actually that is appear to be serialised so I can
Get the inspector
I do want to be private
And I wanted to be a vector 2
Whittaker l cast after
Raycast offset that x
Is replacing what we had there which was a wine to make sure we do it in the debug area as well
And also
What we have control over at the length
Other recast as well
So when are we going to create a new serializefield it's definitely private
Can be a float in a Justin Bieber raycast link
Default 20 I definitely don't want 20 so let's have a default of 2 and we can
Change it in the unity editor
If we see fit
Alright
And how about we add that raycast offset to the trains from that position at y as well
Here we go
Anyone here as well
Alright so what are we just do that guys
Well
We created a new vector to variable that's basically and X and Y value right so curly
Play fault it's really 200 but we can actually just that in the inspector in unity
Play and we've added that to the transformed position that xx so we can have a little bit of an
Set
In the extraction
Nasser in the y-direction
We also have control over the length in that forget about that raycast length
There we go
And also
This as well
A Catholic
And now we have control over the length
And also the offset of the raycast when we go into a unity editor
Why do we want controller with this well because some enemies might be a little bit more precise than other enemies
You had a really fast anime that can run in search of Sprinter crawl across the rooftops tray
Definitely want that recast to be much more offset maybe over here so that he could maybe
He's going to approach an edge because he's moving so fast right
So what we want to do here is just change a raycast offset to be about 1 here
Unless you a raycast length of 2 here and let's be sure we override
The enemy prefab
Alright to play
We have that recast
Appearing to the right here in look even at runtime we can change
How far we want it to be raped wanted to be really close maybe something like that
He gets right up to the edge
Or maybe super far away rain
No change the length so that maybe we want our enemy to be able to fall down a size like this
But we definitely don't want to be falling all the way down so that's why you would make the raycast length like that
So the last thing you want to do here for
Creating these lejwe Cassie's just create a left one as well
So I'm going to do is just copy this
In all we had a newest just
Change it to the word left
And then invite those numbers right
So this is not going to be right now Drake ass is going to be
Left lead raycast
What's it going to make this - so the expositions of the centre
Also - the raycast offset
No because left is only a horizontal value we don't need to do anything with the why
And
Just be sure we change the debug is well here so - here
And when we just change the colour to be oh no green
So they can see the two of us
Ok
That's really all we need to do
To create those rays
Play here
So now we have these raise these lasers that are going to detect and tell the enemy
Where they are in the world
Am I approaching a Ledge let's beat them up here
I'm approaching a Ledge crap turnaround right that's what I'm going to do and that's not actually scripted guys and
Just changing it
Right now but if you touches the air she's going to need a reverse and then as he moves over here
Turn around
That's what we want to do and we're going to do that
I checking
Using if
So checking to see if he's raycaster actually touching the ground
Is actually not that challenging all
Oliver is going to a script here
And
What's cleaner somebody's comments here in just make it say check for right ledge
The end
Check for last leg
One of the reasons why I don't like riding Raker script is because they usually really long
Any require me to zoom out so I'm actually going to
Stream down the size of the Right window there
We can see a little bit better here
Ok
So are we going to do here
We're just going to check
To see
What the right ledge raycast hit
Collider is see when you create a raycast
Hit to die
It immediately will store information inside of this variable
One thing that stored in the information is weather is hitting a Collider ok
Some of the things we can type it if
Right ledge raycast hit centre there.com Rider
If it equals nothing
Well then
Oh man write a letter tray there's nothing below me on my right
I'm going to be back
Crap I'm
Close to a right
Ledge
Decibel metre works
The nearest that I like to test things out
Very often when I'm running scripts
That helps me to avoid getting confused increase the max speed here
And
Nothing is happening
Well the reason why
Is not actually telling us
There's nothing to his right is because there is actually something to his right
And it's something invisible
What is he actually touching
What's go ahead in create an Elsa
Else
Debug.log I'm
Touching
Space Plus
Debug Outlook that is right ledge raycast hit Collider
Object
So what is this a statement doing it saying if I'm not touching anything
We'll get that to the council
Else
If I am touching something
If my Collider is not knowledge actually something then I'm getting debug
I'm touching
What that something is so it's see what we're actually touching to get a better idea
This is why you want to use debug.log a lot when you're making your game
Helps you know those invisible things that you're touching
Oh my goodness luck
What is a
Attaching a polygon camera can finally
What is that
Diaz remember
We have a polygon camera can finally
Wayback
Earlier in the series
And that is actually
This trigger zone
Tell the camera to stop at certain areas
Sorry anime
Is raycasts or interacting with that
That's really weird
Well the way that we are actually going to fix that
Where should you use these things called layers appear in my anime
Can I have this layer
Drop down here
And you know this we have a few layers we have default
Transparent FX
Ignore raycast
Water
NUI
What we can do is actually set the polygon camera Collider to ignore raycast
Now it's a play
Ok great
It looks like he's just touching the ground
He's not actually touching
Anything else
Perfect
Selfie going to enemy here in increases speed just a little bit
Just have to wait for the sun to set
There we go
The nearest that is still touching the ground sticking out picking up picking up
And as he gets to the right here
If it stops
He knows he's close to the ledge
Perfect that's exactly what we wanted it to be
So now that we know this condition works
We can actually
Change
The direction
The enemy
How exactly are we going to change the direction of the enemy
Well we got to do is actually just multiply
Speed
X
A direction variable
That doesn't exist yet sort create that
We don't need this to be serialised because you don't need to see it in the inspector
And if given integers you going to be 1 or -1 right so private integer
Direction
Because we don't have it default 21
If it then he's going to start out at basically
0 and he won't even move
So if he actually is getting close to the ledge
What we're going to do as we're going to set a direction
To -1
What is the recast does it take something to the right
Where is not going to do anything we can keep this feedback here
Let's see if he switches directions
The momentary approaches
In all area
Meaning there's nothing to his right
Set max speed to one year because it's driving me crazy
Perfect
Works great so we just need to get it to work for the left lead as well so how we got to do is just copy
Play a cold here
Place it
And we'll set the direction to one if the left ledge
Raycast
Is stuffing
Save it out here and
Take a look
Looks like we have a no reference here it's causing some issues
And no references basically there is no reference to an object there's nothing set so we double
And it looks like it's saying I'm touching
It looks like I need to change this out to be left ledge raycast hit
Atlas take a look here
What's that his
Max Speed 2
Exeter to here
And a supply
So I can speed it up to get an idea what's going on
Ok ok
Did you guys catch what happened
Teresian why he didn't turn around
Is because
This raycast is taller
Ennis Leisure
So he's just going to keep going down
Because I recast high
Etc long right
So are we going to do is actually just set a recast height or Discovery cast link
1
Now let's try it
Ok so like it's shorter than the actual lead here
So he should turn around there we go
Awesome that's great
Is working just fine I like it ok so now we need to do
Talk about what if he hits walls right if he has a wall is he going to turn around
Actually no let's have a check it we put him
Right here
Tennis move to player
What's going to happen when he touches a war
He gets stuck
So what if we wanted
The enemy to reverse its Direction when it hits
What's
What is actually very similar
A few changes
To what we made for the ledges
Open up the enemy c-sharp script and all going to do is create a new private
Broadcasted
Everyday call this right wall
Raycast
Unless it's going copy there in Crete
Difference between DS
Any leads the right and left wall raycasts actually just going to
Send a raycast out from the centre of our enemy to the right
And also to the left
Check for walls
It's behind
Set up
Steven comments here check for right wall
A very similar code to what we see here
Gonna be right wall raycast hit
Equals
Physics
Recast
New vector2
Transformed at positions but in this case we're going to do smack DAB in the centre
This gameobject
Transformed that position that's why
The comma instead of Vector to down we're going to do vector to the right
NN raycast length
It's fine
Please be sure to debug
The real as well so we're going to copy this actually just paste it
In so all this is going to be is directly from the centre
X and Y
Vectra Tudor right
X x 2 regex length
Just you and I know what's you are so red for right ok so that's going to check for
Double check in see if that Ray is actually being drawn
Ok looks like we can do this so it's being drawn from the centre of enemy
In this rate is going to be used to check if we touch or right what
Alright so let's just ride out the condition yes
Write wall raycast hit
Dark lighter
Does not equal meaning if it is touching something
Dennis debug.log
I'm touching a wall on my right
NN what are actual Collider is so right leg break cast hit the
In the game are checked that back later is on
We can save it
Back in the Unity
In a Future episode guys we're going to clear up all these alerts so don't worry about it for now
Play
Ok
That's great
So
He's going to
Just look for
Wars
That's great
Ok
So he's touching walls and his right
And so now we can go ahead and just set the direction to equal -1
Australia see what happens
It looks like it's behaving in a way that we don't want
Let's see what's wrong here looks like I used
The wrong raycast so he needs to be right wall raycast hit
And also in the debug here right ball raycast hit that
Relations you smarter than me
Artist need
Semicolon
And now hopefully
What's the what's going on
Play
Ok so
We have a wonderful
Here
And
Langley Priory part of it again congratulations you smarter than me
And honestly guys
I need this is gonna happen and I wanted to show you how we can fix stuff like this so you never said a raycast is
Omitted from the centre of our enemy here right
That means that it's touching
The anime so touching itself
We really don't want that so the way that we can solve this is actually through a thing called
Ok now in this project there are two different kinds of layers ok in my hair
We just created players here
Anita parallax layers don't worry about these kinds of basically away for me and you
Very is parallax layers ok that's one kind of layer
The other kind of layer were going to talk about it over here some of you may have seen this word they're here
We can actually create new layers ok new layer just go with me for
Let's call this the enemy player
Recording about layers we can actually have certain objects
Better in a certain layer
Ignore
Other layers ok
So we can actually set the layer 4anime.to
Enemy
And then
What we can do
Is we actually can go into the Script
Until our raycast
To ignore
Specifically
So we can do that is just go comma
Recast
Layer mask
Set variable doesn't exist yet
We got a creative up here
In so we'll see realise this the silliest serializefield
It's going to be a private
Layer mask
Is going to be called raycast layer mask
So
All this means we've added this new parameter here and it's just a parameter for the physics2d raycast
It allows for us to have a layer mask ok
Does go back into unity
When you see it appear here
There is
And that start with everything ok
We want everything to be selected here we want this layermask to interact with everything ok
Well we definitely want it to ignore objects that are on the ignore raycast layer and that includes the polygon
Camera
Collide remember we had this year and we said it to ignore raycast
So we definitely want our raycast to ignore that
And we also wanted to ignore itself the enemy
Play here
So now it's not going to touch itself
We definitely don't like our enemies touching themselves ok so
It's just go ahead and copy all of this and paste it
Where to check for a left wall ok
So there's gonna be left wall brick acid
Just going to put that
In here and here and also going to
Vector to that left
And trying to think of anything else you're a doctor that left in order
I think that's everything guys
The colour is
Different colour purple
Is there a purple
Purple magenta
Take a look
One final thing
I'm touching a wall on my
Left here we go
Supply
Is touching a woman's right
Now if we change his speed to mega to
I'm touching a wall on my left
Awesome
Are we going to hear it
Remove the door and just change the direction to be well if you touch a right wall
Siri -1
And then if you're such as a level the direction is going to be
Positive one
Perfect
Now he's stuck
Define throw him up here
Great so we can't fall over ledges he also avoid
Player
I really want that because we want him to actually
Put the player in engage with the player
So why is he avoiding the player
What is because he thinks the player is a wall
That means we need to set the player to be ignored
By that recast
So is there anything on our list here that allows us to ignore the player while the player is on the default
I just show you really quick
The players on the default layer in a guys I cannot stress this enough these layers here
Have nothing to do
With these layers here ok
These layers are just a way for us to have parallax layers and we can name these honestly whatever we want we can call
Parallax one right so that's really what these layers here is it just game objects
Where is
Recite the player here
This layer in the inspector
Basically helps us ignore other game objects that are on that layer so just keep that in mind
Two kinds of layers here
So
Curly the player is set to the 0
Maya which is called the default layer
What alarmed gameobjects are actually on the default layer as well
So we really don't want
The enemies re cast
To just ignore
The default are doing
So what we can do is actually just
Create a new layer
Call it player
And then set the layer
For the player
Player
So now the player is on the layer player
It's all we got to do is go to enemy here
Just make sure
He's hacking interact with himself
Is that alright with the player
Worthy ignore raycast layer
Play
So far so good
Dragon appear
So he now will chase after the player
Alright in hit the player and her two player that's great
Alright
So now we have our enemy able to pretty much
Ignore ledges
And also
Eleanor was now case I just made a break so far
He is looking pretty good alright guys so not we have the enemy able to sort of Patrol around the level
We now need a race and code that will actually hurt the player
So let's chapita enemy script in what's writing pseudocode
Let's see hear something like
If I collide
With the player
Supplier meaning his health is going to
Decrease
And then we also need to update the UI
Ok so how is actually do this
Well if we go to a collectible script just for reference memory have this ontriggerenter2d function here we also
Is there any Gate as well
Well we can't really use that on the enemy because the enemy isn't a trigger is it
A Collider
Take a look
Preselector enemy here you can see that the capsule Collider is Trigger a set of false memory a trigger is meant to
Passed through the enemy is a solid entity right so we need to use a different function
It's very very similar
To the ontriggerenter function used in r collectible script
And also our Gate script into
Chrome
Images Google Unity on collision enter 2D
So because we are blaming here we're just going to literally copy and paste this
So let's see here
That's great right there I just copy that oncollisionenter2d right
Nails for us to check
If we collided
With something else ok
So let's just go to your enemy scripture
Studying
Remove this debug here
Are we going to do is your guys if you guys just smart enough to know this now
If we consume in here and go if
Call
That's the very one name here in the collectible it's collision and as a collider2d variable type
Enemy script a collision
2D variable type
Honestly
I'm not a huge fan of the language because it's very similar verbiage so
Oh no just have Google handy here alright so if call dart game object
Equals
Remember what we can use year the incidence
Pattaya
So if it equals the Instance of the player
When are we just debug.log
The player
Semicolon
Play they're out
You're back in the universe here
And let's see what's going on again guys
In fact if you want to just buy them for now what do that
For the course with making games
There we go
We hurt the player
Perfect
Ok so let's go ahead in decrease the players health
Every time we get hurt so currently our house is it 50
So let's just jump into a new player script to use dragon over to hear my clothes out the gate script in the collectible script
So it's just simply do this
New player
The Instance
Health
- equals
An end
New player that instance
Update UI
Decrease the house by 1
And then we're going to update that UI meaning the health bar is going to reflect the actual health
Save it and see what happens
Shrink down is a little bit there we go
Jealous
Keep an eye on the Health over here
The player
And
Right there we go
Are we getting hurt pretty good here
Awesome
Ok
So that's hurting us a lot actually
Exactly what we white
Angel far is also updating and it's perfect keep an eye on it we could that slowly shrinking down
Something we can do here is actually
What if you don't want to decrease by 1
What is a decreased by
A custom value so maybe
Power
A Better World is probably attack power ok
The variable does not exist so we need to create it up here
Just put it right here
We're going to see realise it
Private
Where's my container joke
Ninja makes more sense when I going to have like 2.5 being the Ripper I think maybe a value of 10 is
Better option
Integer
Attack
Power
And will speak to the default of 10 that we can definitely change it if you want
Unity here
My Selector enemy here
Now we can actually tweet the attack power
So if we wanted to have let's see here one enemy that attacks a value of 10
In another anime that attacks
Add value of I don't know
50 we can make this with Michael is scary alright maybe bacon
Vibrant
Louis Marlow
Big and maybe make it too
Big enemy type here now that can hurt the player a lot more
Play
What's a player
Little buggy bear the Ricoh system isn't really meant for these Gia
Enemy types but you get the point you're so if I get her here so I went down by 10
Went down by 50 right-hand dead now
Enemies are now attacking the player
Really simple really straightforward
They can be great have an indication
That we're getting hurt
We're going to be doing that when we actually create animations
For this game
And that's going to be during the animation portion of this tutorial
Just yet
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.