All language subtitles for lesson096

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian Download
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Creating an actual inventory system is

Cattle are more challenging than just creating coins and health

An inventory system might allow us to collect keys and maybe various objects for fish

Quests that we can add to a inventory

So what I want to do is first and foremost let you guys know the inventory systems or very.com

In most games

How to create a very simplistic inventory system here which was show a collected item so let's say

Key

It's a pop-up in the right-hand corner over here

And if we use a key it's going to disappear

And also guys for the purposes of this course

I'm going to only allow for one inventory item being held at a time

I know that sounds like it's very limiting by believe it or not even never song my recent release on switch

Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1

PlayStation apple Arcade

Only allows for one inventory item being held at a time

So how exactly are we gonna start doing this

What the very least I know that I want to create some inventory item indicators

Does jump into rui and double click it

I know I need a slot that shows up that's blank

I just got a new layer

Select the

Ellipse tool here so click and holding make sure it's all selected

Ian let's go ahead and create a lips here

Now you never said a squash I can make all sorts of shapes year old shifts so it's a uniform circle

I'm really create about right

To make sure that is filled with white

And make sure the stroke is 9

Just be sure you select your Move to when you are moving around and if you guys are struggling to see

Is transformed controls

Resume and you can see it better

Rotating or scaling

Simply because

You need to make sure that when you've selected the move tour

Show transform controls is ticked

True

And where

Is also selected

No it for some reason you've deselected

Your circle here

If you have parcel acted

If you want to select the circle you can either select the layer here or

Select

Remove door and press ctrl and click

And now we can move it over here

This is going to be our

What's 3 name it inventory

Link

My sister blank slot right

Does jump back in the Unity

Input there

Rui

In the canvas

Import

Selecta you I in actually got a spray editor you just make sure it's showing up

Let's go to our

Black back on here by clicking this button is going to show us

Ok

Give us a better idea of where it actually is so it's like I got moved all the way down here so there is our inventory

That looks great

So let's go ahead in bring this into a UI canvas

Talking to do as well just to create a new game object

UI

Image

Ok it looks really big but it actually really small on the game view

How much is dragon armour here

Guys remember

How to set the Anchor Presets

To the top right

Perfect hairy girl

Just because I want us to be perfectly in line I'm in a drag this over all the way over here is zoom in some close

Looks like you're about three-and-a-half 3 and a quarter for three three and 3 quarters Square

Where is grade units

Away from the left

Side of a canvas so

If we just drag over to the right

News similar principles so 3

27/5

Units from the right

That's fine and take to be too picky here so we got a square here

Now let's go ahead and drag that inventory blank into the spray field

Here we go and then just let me decide

Alright

So now we have an inventory blank so it's just a little circle here

And

Little Miss alive now that we've said the size Drake there we go

Alright so

Is dragon animal

I must be sure to rename this

Inventory

Adam

So basically what we're gonna do here

Is when we collect a key

When it's added to your inventory

We're going to add it to the inventory

Via script

Also going to indicate that we have that item

Am I going to replace this blank sprite

With

80 sprite

Example

Tesco heading Creed that he spray really quickly

But jump back into Photoshop nearly there click on Photoshop or you can just double click on

UI for a shop aisle

So we have a blank inventory item

Just got him create a key

Now we're going to get into actually doing artwork

In a Later series sofa now which is going to Google

Google Keep yng I would like this one so let's just right click on it say there's

NN

Save it in a download file

All I do is just click on it it opens right up in Photoshop

If it doesn't open up in Photoshop on a medically

Just be sure you go to your downloads folder here right click go to open with

Nazi Photoshop you can choose another app and actually you should probably do it this way anyway choose another

What's the time for the shop in the news always use this app to open png files

How to make things a lot easier for you

Once it's opened up in Photoshop I'm just gonna press control a

Select this entire

P&g care and control see that's just edit copy right

Going to my UI file here in control via that's just pay store

Pace

Ragged on over here now if you don't see any controls

Taxi scale

Because when you have

The move tool selected here

Show transform controls is not ticked to true

I want to make sure that the layer is selected here

That allows me to actually

Click on this

Any more

Suck my life

The way that I select a layer is I hope control

And then now I can click

So you want to select something

When you're using

The move tool

Control

All sorts of stuff

Torquay

The transform box is showing up so we can scale it down just a little bit

In the present

Now it's been Transformed

To a smaller size

I'm going to put it I'll have a bit centre here

Shift

Just tried to the 11 I cannot allow us to actually drag along the x-axis in Photoshop

Last thing we want to do image adjustments invert

Invert from Black

Be sure you name it inventory

Key

Remember guys I like to name things with the broader category as the first word

Any more specific category

At last

So it's a broad category of inventory

Any more specific category of key or blank

Or maybe you get a flamethrower or maybe you get

And I Know It trophy

You slowly get more specific

As you go down a line of words to the right so

Generic then specific

Alright

Save

When is John back in the Unity

The import

Awesome

And as you can see we now have an inventory key

An inventory blank

So you may notice something here

We're going to the you I hear you got a Sprite editor

We turn the background black just for the purposes of looking around in zoom in and then click the middle Mouse button to drag

You noticed that the key is much bigger

In the inventory blank

So what that means is

If I swap out this inventory item

With the key

She is really small

How can a we're being wanted to be Dad

How do we solve this

Just going to Photoshop you

And this is actually a really simple trick that you can do

Resume in

And that's with

Prezi and then ensure that scrubby zoom is turned off I really don't like scrubby zoom if you want to use that

But I turn off family room in the night

Zoom in here

Prestige

I can see that this size

Is a little bit bigger

And this one

Press ctrl click on this

See that

It's about 100 pixels

That bloke all out there showing the size there about 100 pixels

100 pixels

So let's go ahead in try and make this 100 pixels by 100 pixels

Even being 100 pixels by 100 pixels it'll make sense in just a second

So we have this inventory blank layer selected

You can duplicate it by going to right click

How much is name this inventory blank

This not really matter just me so it's just presenter here

Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1

And now we can actually scale this up

That big here double click

Or press enter

And now the transform has been confirmed

In luck we can change the opacity of this layer

Bring it down to 5%

Now it looks like it might be a little bit bigger

Dennis key

How we know they were hitting the exact size of this key

Why should go to view

And they make sure your rollers

Is ticked to true

And all that means it's going to show these rulers here

The cool thing you can do it is rollers actually create guides

But you want to make sure that those guys actually show up

So when you got a view

Show

Make sure guides is turned on

Drag these guides down

It looks like the top is about right here

And I will do another one drag down

There's the bottom ok

Looks like

This needs to be moved down a little bit

Let's make a little bit brighter

We can see area

I like both of these holding shift

Excited both layers

And now I can actually just scale it down and move it down

As one unit

Here we go

Know if this was maybe over here like that

If you select both layers you can actually just sent to them up

Using is a line tortilla so that's the vertical one

When is the horizontal

But now it looks like it's exactly the size of the key

And I really like that Alex great

So

One of the ways we could get this to work is simply just convert this to a smart object

And that basically put everything into one file so I can double click on this if I want to change

Things so for example if I wanted to make a

Can I make this right or something

Just save that

Go back into my UI file

Can you see it updated

Basically when you create a smart object create a Photoshop file inside of a Photoshop file you only just

How unity sees this there because the moment you import this into unity or just updated inside of you

It's not going to see another Photoshop file it is going to go all that's another png layer

Don't worry too much about that

So we do it that way

And now we have one image here

And us go back into that so just double click and

Let's make it white again

And save it out

And it looks like we're going to go

Don't forget to rename you later

Tell us to inventory

Unity remember that this is the blank inventory item

Go back to where you are I and go to the import settings and then Sprite editor and take a look when we can collect this

Ok great so now we have a black background

It looks like we're getting close we want this to be the exact same size so that when we swap them out

You collect the key

The sizes match

What looks like this one is 103 by 1 and 3

That number how about 105 by 105

Again guys what were changing here is not the size of the p&g

Where does changing the size of the cut out

Other png

This is literally looking over transparency with these printed Sprites on it and you literally with an exam

Cutting out the Sprite ok

So this one here was just thinking the same thing 105

Bye 105

We go

Does the inventory key and this is the inventory blank

Reply

Alright and then xlove are spray editor

And you're still no it's small and that's ok

Manchester concert need a size here

Awesome

So what happens that say if I use the spiky that's tested out

I use the spiky

Script that will say

Swap it back to inventory blank

Sweet turn out a blank inventory item some of you might be thinking Thomas that kind of looks like an item it doesn't

A blank slate what would you do is actually just jump back in the photo shop

Open up that smart object for the inventory blank Sprite that is double click on this layer

This bigger circle to something like 1%

If you make it 0

You know these girls can I get confused and shrink down

That's sliced size

Remember we didn't actually save the UI file we only save the smart object so make sure when you say this

Project with ctrl S jump back into your new wife I'll

And then it save again

So we're going uni here it's going to automatically update this

You can't even see that circle

It's still exist you can barely see it

But I think for the purposes of this tutorial

That looks great

Against the reason why we added this faint circle

It's so that when we go to the spray editor

Internet background black

It doesn't put these up really snug with each other

Allows us to create

Same size for both of them

So that we can swap them out with scripts and you're not going to get weird scaling issues

Ok

So we have a blink inventory slot

That will be swap down

When you collect a key for example

With the inventory key

Sprite

I just collected achy right that's how it's supposed to look

Alright let's do one last thing here let's just double check and make sure everything looks good and various sizes

Can I suggest you guys double check as well

Sweet looks awesome

Everything was good at various sizes no matter where were playing this game whether it's on your Xbox PlayStation

Apple devices anything is going to look great

In the next section we can talk about coding this inventory system and swapping up that key

So this is where the fun begins now that we have the UI for the inventory

We can collect so for example a key

I need actually write some script that will throw the key on the screen and also script something that place is that

Into some kind of variable

So instead of creating a whole new script

For our inventory

Because we're going to keep things clean and simple we're going to put it inside of the player screw

I told you guys will be using the player script a lot

Set up new player

And working I create a new variable type

Call

Dictionary

Now

It's not like an integer it's not a float it's not bullying

It's not a vector to it's not about 3 it's a totally different type of variable and it's a really cold

Because they can store values inside of it

So let's just write it out in don't panic it's going to look weird

But it all makes sense to you eventually I just trust me guys just keep practising

Where to take the public

Dictionary

Ok like a dirty telling us how to write this

Ok so can I use these less than

Integrated hand signs

So what we do here is type string

And then sprite

What the heck Tom is what is this mean well first of guys I wanted to be on

I'm looking

Add unity documentation right now

Ok

I don't memorise this

It's okay to not memorise

Complex variable forms like this

So it's ok love things up

Basically what this means is were going to store

A string

M a sprite

Inside of this dictionary

Ok dictionary as being able to say that one

Of the dictionary is going to be

Let's see

Gym

Along with

C1 sprite

That's basically what this dictionary is going to allow for

And technically we could do a tonne of sloths here we could add a ton of inventory items

We can have slight too

Is there any equal

About gem key in ASDA string

Nng sprite

Jam key spray terrible terrible name

Get the point right so that's what are dictionaries for it's really abstract right now I think in your head right now

Pretty blurry right

It's gonna make sense I promise I just keep going I find I just

Going and keep what is the song Tori sings just keep swimming right just keep swimming

Keep going and it's going to make sense I promise this dictionary

So let's call it inventory

Now what I done yet

This is weird syntax and it's ok to reference unity documentation

Equal

A new dictionary

String spray

There we go

And close out

Again guys this looks weird right I would not be able to memorise this my memorization skills are

Brenda's

It's ok if you don't memorise how to do this

Simply copying and pasting is essentially

Communities documentation

What does matter is I know

That we need to use the variable type dictionary

To store inventory items

So that's the important thing

Get rid of this

David out

And the next thing we want to do

Is wee white

To start to add

Some inventory items and see if it works ok so let's add

The key

Inventory item ok

How will we do this

Well

What's tested

In the start here I like to test things out in the start function just to see if it actually works

Ok

So I know you have a variable called inventory so I can do inventory and then I can do some poo

Functionality

With this dictionary

Variable type

Actually use the word hadn't shown up right there

Ok cool

My apprentices

Ok so I can add a string value yeah there it is and I can also display value

Ok so I can add a key one

Are you comma

And then some Sprite so key sprite

Say that out and

Make sure we

Close it out with semicolon

Why is this red zigzag appearing

The name keys bright does not exist in the current context

Ok so we need to actually create

A Sprite variable appear

Cos it doesn't really know what that is right

Just got hen do that was create a public sprite

He's sprite

We need to do for now

Back in the unity here

Chucky's bride is going to show up

In

A new player

Composer here

Realitatea

So now we can actually have

The inventory key

Ok

Does clear the console save everything

AirPlay

Ok so

Nothing is really happening but

I'm pretty sure

We are Anarchy right

What does debugger to see if it was added to the inventory variable

That inventory variables in a shop anywhere is that going to change or you I currently it's literally just this

Abstract variable floating in the abyss storing information

Is there is this weekend at sea

Flog It and see what we get

Debug.log

How about

Inventory

Is it save

Back in unity

And

Hit play again we get these warnings all the time don't worry about your warnings too much you need to fix them eventually

Let's go down 1920 by 1080 so we can see little bit more here

That is very confusing lochia

Looks like it exists

It says

Dad

Inventory is systems collections generic dictionary with a string in aseprite

In so you can see that it's kind of logging something a little bit abstract

We get a little bit more specific

So it's really telling us what the inventory is which is a dictionary

Variable type

Inventory

And it looks like we can do something like this

England Tory

Mm2 a bracket and a left ok so this is kind of like maybe you can remember matrices or

Arrays in math class is kind of what this is

So we have these brackets here we can actually find

What the spray is

For the string key one so little was looking up I must like when a dictionary lookup

What's the spray associated with keyone

That's pretty cool

Just read it and see what happens

Awesome

Inventory key

Is the Sprite if literally like unit is opening up a dictionary

I'm looking for ok what's the spray associated with T1

Tells us

When we asked it to be logged into the console window

It tells us that it

Is right here

Inventory key

What's Lyca dictionaries working

That's great

It doesn't make sense guys we can keep moving and hopefully

Little Mix it actually promise it's going to make sense because really using this a lot

So just a game a little bit of understanding of how exactly we're going to set this key image

To swap out with this blank images

Just do it

In the start function just a test Adele

So let's go into the start function

Of the new player script here

We've added the inventory right

Denim overalls going to do is we're going to say

That's bright so some pseudocode here

Blank sprite

Should now

Swap

With the keys bright

Ok

How to do this

Well

We need a reference

To that inventory sprite

Torch first create that reference

We're going to go ahead and put it here where to call a public image not a sprite

Again if you go into unity here

Inside the inventory item

Reusing the image component not a Sprite component or the Sprite renderer component

Reason the image

So we need a reference to this so if we go back into our script here

Public image

About inventory

Sounds about right

So what does it allow us to do is actually have a reference to that inventory image

We don't really know what it is we haven't told unity what the inventory image swap even is

So we sleep player you can see inventory images showing up

So we can just drag this

Here

This gameobject is called inventory item

So it may make more sense to me because inventory item image if you get a little bit

Naming your variables is really important to make sure that you're not confusing yourself in the future something kind

Inventory item image is fine so if you actually change the name of a variable

He's going to get confused in lose that reference so just be careful renaming variables

So we can just go and drag inventory item again

So

What is going on here

Well in a new player script

We have a ton of references to a lot of

You know global address going to be using throughout the game

Select inventory out of here

Highlights this and says ok my reference is

This image component

Why do I need to reference the image component

So they can swap out the inventory blank with the inventory key

Right so we have that reference

If we go

Back to the new player script

Weaken below the pseudocode here

In all we Gotta Do Is go

Inventory

Image

That sprite

Equals

We could do key spray if we wanted to

Don't say that and I'll show you how it works so we going to be here

Because this is in the start function

A moment we hit play

It should swap that out with the key

There we go

Ok

Why is that not enough well we need to build 4 scale go for a scale means you're building a system that allows

Functionality in the future

Now we don't want to be so specific here

So what we are rather do here is good want to swap the sprout

With

What the actual string is so that's why using a dictionary because some objects are for example

Trophy is going to have a different sprite

Or maybe a chainsaw is going to have a different sprite

Right so we want to create code that allows for scale in make it reusable

Inventory item image that Sprite is going to equal

Inventory

Remember we can use

Brackets here

And we can type T1

If you can recall when we printed this line of code to the console window

It was out pulling

This the key sprite

Let's save this year

Engine builder unity

So it should perform the same sort of functionality but we're just doing it in a little bit of a different way

Perfect so we have this key Sprite showing up on start that's exactly what we want

Play mode here

Go back into a scrap

So you may be wondering

Why we need to be riding at this way why can't we just reiki sprite

That's because we're going to create a function that allows for us

2

Removing add inventory items over and over again

Without getting too specific

With spray we want a deal

I know that sounds confusing but just bear with me

What's go ahead to create a new function ok

That's where it is

Create a new function

Let's go head go down here and we'll call this

Public

Lloyd

Add inventory

Ok

Creating a new function called add inventory item

Remember the syntax for creating functions is a little weird

Ok

So now we're going to have

This line of code

Copy that delete it

I'm going to pierce that inside of a add inventory item function ok

So technically everyone at do we can just go into the start here and go add inventory item

You just gonna buy this line of code is double check

So you absolutely 100-percent believe me

Hasting that code into the new functions

An infinite function inside of a star

Is just fine

As you can see

The key

Swapped

So far

What is this function what is this ad inventory function can allow us to do

Remember you create functions in C Sharp so the chicken use them over and over and over again so they don't have to keep

New code at all very similar to one another

What is creating 1 new function that can do a lot of different things

In this case we want to add inventory items

Based on new strings

A new sprite

Create a new function that's going to allow us to add

Different kinds of strings so IKEA trophy

Gloves boots alternative inventory items

To our player

And also tell unity what does Sprite even is

What we can do with something really cool with functions

Not actually add parameters

Remember how when we created this dictionary

We said we can pass in a string

And also a sprite

Tony's case where passing inky one

Anansi sprite

You can do something similar when you create a function

Security pass into a function

Parameters

I know that sound weird

Go with me for one second

If I said add inventory item

This printer sees basically says

Hey is there anything you want to tell me to do specifically

Well we can actually pass in some parameters

So what if I wanted this ad inventory out of function down here

To be pretty specific

What's the one of the 82 instead of 81

What if I wanted instead of the key Sprite what if I wanted like a gem coloured spray

The totally different spray

Well you can actually use something called parameters

And basically make a function

Customisable

In in specific to the information has been passed into

Search for appear in take a look at the Calling of this ad inventory item function

Play some pseudocode

I want to add

In inventory item

Key

With a Sprite of

Ice Age MP

What actually do that with these printers here

I need been wondering where it is precious is even here for when you're calling functions well

So are you doing something like

String of T2

And

Tim key

Bare with me I know it looks a little bit confusing but all were trying to do is

Add an inventory item of T2

With the djembe sprite

Doesn't work exactly just yet we need actually tell the function what the parameters

Right so we actually need to say

Well you can have a string and that's going to be the inventory name

Karma

Aseprite

Call Ben

Image

How you doing is creating this

Temporary variables

That we can pass information into

In reference those

So all we do is change this out from T12 inventory name

And then we change this out to image

So I know it's confusing

Just bear with me here

Add inventory item here

Dysfunctions mean called

Were passing into this function

T2

So literally because this is in the first

Slot of the parameters

It's saying ok watch string

Can I pass well

This inventory name is going to be this ketu

Inventory dad is going to add

Ketu

Inventory dictionary

Is going to add the gym key

To the inventory as well

Why you can see the gym key is

Zigzag that's because we have an actually created the variable here

So let's just go ahead and read that really quick

Baby change the name of a little bit something like key jam

Brighton

Energies can be there and we'll pay that here

Say it

Now

Add

This

Your inventory

It also

Simply

Set this to

Whenever that inventory name is ok

Here we go

So now we've created a function

That allows us to add inventory items of whatever we choose

Confusing so what we're going to do as we're going to save this

How can I help play

Just going to make sure it works right

So so far it's broken it's confused

Why is that I'm glad this happened

If we jump back

Into a script here

Younotus

We passing the gym key sprite

The nearest when we fired the add inventory item function

We were able

To set the inventory item

String to key 2

Add that your inventory

What does ygm spread even is we need to make sure we specify that

In the parameters of jump back in the Unity

Can you can see hear or keygen Sprite is nothing right

So let's just go into a UI here

Photoshop file

So let's just right click on this inventory

Current duplicate layer

To call this

And draganova

Just use Jasmine's

New saturation images colorizer

If a colour is here maybe make the line is a little lower

Bring up the saturation

And let's make it a gem colour

That green

Turn that down and if we go back in the Unity

What is important we now have the inventory jamke

Remember we want to go into the spray editor just to double check here

And make sure it's sized appropriately

Remember this one's 105 this ones 105

21 of 5 as well

105

And that is an image rage MP it's just wait because we've actually invert the colours

Turn that off

That's perfect

Reply

Sprite editor

And remember guys we need that reference

Tell inventory key jam

Where did driver Torquay gym spray

Here we go

Now

When we hit play

That green junkie is going to show up

There it is

I'm sure a lot of you're watching this right now I'm thinking I don't know what the heck he just did

Turn on blame you guys I feel the same way honestly I've been there I know exactly how it feels to just have

Abstract code thrown in your face and it makes no sense

I'm going to do a quick recap

We create functions

When we want to use code

Over and over and over again

Technically I could copy all of this information in here all this code

And paste it here

It will do the exact same thing right

What I want to do it here too

I got redundant code I'd like cold all over the place

So that's why you put

Simple lines of code

In the functions

The problem is sometimes you want a function to be a little bit more specific and not so generic

The Way You Make It specific so for example if I wanted to add a key or a boot or

The way you make functions more specific will also ensure that you can reuse them

Is you pass through what's called parameters into your function

So I have this function here and I've told you nearly that I want this function to pass in

An inventory name and a string variable type

In an image

Which is a sprite

I can pass in those two things

NN

Just have the inventory ad functions fire

In regard to use the inventory name so whatever we set the string to

And also this image

Which these two are linked here at least your link here

What we're not just adding

A blank image we're adding the image that we said to use when we call this function

So the images keygem sprite

And also

Keytool is the string

Ok so we fired this function the moment unit B starts

We called it

And it's going to pass through

The string key to

Is it going to pass that through to here

Add to the inventory

Eventbrite

Pass through

Tahir

Almost like a game of telephone except in this case he never screws up

Right it's always going to know exactly what you want to do

Because it's just saying ok you said to you too

I'm gonna add that here

You said keygem sprite

I mean it had that here

So what we can do all sorts of ways

Add inventory item

Cat

And then we would just

Say what's the spray was called cat spray

You do a times you can do it all over the place

You can do it here if you wanted to

You can do it here if you want to do it

Because this function is public

We can actually do this from other scripts as well

So what if we wanted an enemy to be able to steal your key

Or maybe an enemy gives you a key

You can just use this ad inventory I don't function from that script as well

And it was just

Call this function here

And we can pass through specifics

About function

That's really all this is

Listen guys I know I said it's a lot

If you're confused it's ok

Seriously it is ok

Just keep moving along with me it's going to slowly make more sense

Because when are we doing this a lot

Passing through parameters through functions

Where is variables

It's gonna make sense I promise

Just keep going going to make sense

Alright so now that we have this function written

We can actually start

Creating

A collectible item that looks like a key

Habitat to work inventory

For we do that jump into our new player script and just clean it up just a little bit

What to do this often throughout these tutorials

To make sure that everything's clean when I confuse here

I don't really need some of these comments I like to clean so my comments Deramore pseudocode

So don't get confused here

We also don't want the key being added anymore that was just protesting so

We can remove that we don't want to start with the key

You say that out

And let's see hear anything else I need to clean

So far everything looks pretty good here

Say that out if you guys need to add any comments to your script to remind yourself of exactly what's going on

Feel free to do that right now and click cars

Remember

You can add comments

Using two forward slashes

So let's go ahead and create a new collectible type

What's this first as a game object and then we can script it have to be created the game of chess

Zoom in here

Using a scroll wheel

Inlets

How to take this health

Prefab copy and paste

Alex Grey

Now one thing we could do is we could just go to the spriterenderer here

And

Just change out this coin

With

The key

Will you do that

Well the problem here is that that's actually a you I love it

Clear night you you are on it's a little bit different

Then the actual game on Jackson Sprite in your game right in the actual world

So what I like to do just to be careful

I want to actually have

A separate image for what's in the actual game

Because he had any kind of icons on it for example if you were playing on the Xbox and you want to

Use the key you might have a little y button icon overlapping the key

It's really a UI element

You don't really want that reflected in the game world

So I'm going to do is right again a double click on level one here

I'm just going to create a key

Inside of this Photoshop file as well

Just going to duplicate this over to level 1

The right click and just go duplicate layer

We actually choose which document we duplicate this layer into so we'll choose level one

Ok

And now we have this key and we can actually see oh ok it's pretty big

So we actually just scale it down here

Here

And I'm just going to call this key is not really in inventory UI element adjuster key

Say that

And jump back in the Unity

Once it's important we can just double check in the spray edit

Remember we can't click this

It's going to dark and everything

Yeah we have a coin here

We also have a key here

So

That's fine we don't actually need a match the sizes here

Because

The little bit different than you are

Surrey XL this I can show you really quickly here for you select this health here

I just swap it out with the key

Good

Like a proper size I like it

So we have a tea here

Be careful though

You want to make sure we create a new prefab

So let's go ahead

Scroll down for prefab folder

Shall we name this too key

And we're just going to drag this

What can I use in original prefab

Ok

What else do we need to do for this key

I don't really want at Red so we're going to do maybe white fine for now

And I also want to set the item type 2

In England Tory item

Will you have anything in here we have coin health m o

We don't have an inventory item

Does double click on a collectible script in just make sure that we add

An inventory item

As well

Say that out

Go back in the unit

And then if you could the dropdown for item type

If you choose inventory item

Shall we apply the changes we just made this key

The actual prefab

Clicker player

So when we had to go into this prefab here you can see the inventory item is set in it's also white

Alright

We have is inventory item this key

So how do we actually ensure that when you collect it

It does we want to

Play

Just to double check and make sure everything's working

University is no longer updating because we remove that code from the start function

The health

What's good

I can collect the key

But nothing's happening

That's because we're not actually firing any functions when we collect the key

So we need to go outside of the collectible script

Like that

And because I want you clean freak here we're just going to remove all of this comment it all staff

Need it anymore that was mainly just for reference

We met up with between a place as well

Alright

Remember we have these conditions here

If item type is a coin

Then do this

If I don't type is health then do this

Is Adam type is going to do anything well that's right another else

About else if

Item type

Equals item type dot

It is

Inventory item

Then

Do something you want to do

Well that functions we wrote a new player

Is function here and inventory item

Now it's starting to make a little bit of sense hopefully so what we're going to do as we're going to say

New player because member that function for adding Inventories inside

Our new player

Dad

Add inventory item

Well

What do we want the inventory item to be

Well let's just say he 14 now

Add

A Sprite in swap it out

What spray is

Well remember we have this variable here

Key sprite

We have inside of the player script

Because we might want to use this key sprite

All over the game

We can just write

New player

Ducky spray

And say that out

And hopefully when we collect this item it's going to swap at us pray for us

For that code compile

And then hit

Play

We go at The Moment of Truth

Let's grab that key and hopefully it swapped out

It is we just got a key

There's a couple of things we can do to make this a little bit more I guess robust in reusable

When I was going to collect the one are we

So

Why do we do this

Inventory string name

International string

That's a variable

And it's creating a shred exam because again

Doesn't exist

Tell

Let's go how to create a new variable

In the collectible script when I called this

Private

String

Really call this

Exactly what we just typed

Inventory string names

And buy the faults going nothing right

We want to make sure that it's serialised so that it shows up in the inspector

So we're just going to type serialise

This area

Now

When we go

Unity here

Actually click on this key

Look

No I haven't even tie string name

So weekend had it be whatever we want we could have

Hijam or

Kie25

Orchy

Doesn't really matter he won now

Well

What's a little bit more specific

When we actually wanted to identify

The sprite

That's being used from here

Instead of

A generic key Sprite store globally in the new player

We can do one specific for this collectible

That sounds pretty cool

Serializefield

Private

It's going to be a Sprite and we're going to do

Inventory sprite

Now we can instead of doing the key Sprite we created earlier in the new player script we could have won

Specific to this collectible right

And that is inventory

Sprite

So just for purposes of this tutorial

If I was in miui and I wanted to create

Don't worry about wearing this guys I want to create a little :-)

I could call this

Smile

David

Unity here

And wait for that import

M and I could just literally drag this smile to my inventory spray

And I could call this inventory name I love smile

So we got one of the collect a smile object in the game well I can run over here and

Jump to grab this key

We just got to the smile

As you can see this ad inventory function is really valuable

Because it allows us to add a specific

String name for the inventory so in this case you collected a smile

You can also choose what that Sprite should look like

When you actually collect it here

Obviously we need to update

Display here with a smile for example something like that

I think you get the point

Now we can use that functions for a time of different inventory types

Now working on this ad inventory I don't function

Wickedest go ahead in create a remove inventory item function is well

There's a lot of ways we can do this I mean to do it in a way that makes the most sense

2 beginner coders

Again it's plenty ways to do this

Copy this function and create a new one will call it remove

Imagery

Adam

We can just literally change this ad to remove

And then also

When you're removing something from a dictionary you actually don't have two parameters are you have is this one all we need is

Inventory name get rid of this parameter as well

And then we also want to set the inventory item Sprite we don't actually have that Sprite reference

Actually the Creator

Up in a variable here so we have the key Sprite we have the key Jim spray that's another one public spray

Inventory

Adam blank

That's great

I just put that right here

Inventory item

Blink

So now we have the add inventory item function removing inventory item if we want to

Last thing you want to do is just jump back in the universe

Theremin player and just make sure that the blank inventory item spray is set

So we wanted to be this right here

Tell member if we go here it's right here just drag

That's great

So that will allow us to remove inventory item

And also add an inventory item with those two functions

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.