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
What we're gonna do now is really going to have the
Health show up
On screen
And this is actually a really simple thing to do
Are you going to do is actually create a new UI element so I'm going to do is go to gameobject here
TUI
What should I do with you I text
Alright so what just happened here what will
If you zoom out
You can see that there is this Square
I just appeared what is this thing
Guys this is your little canvas
This is basically
Right here
It's this
3840 x 2160
Parks that allows us to place text
Intuit
So it's scaled really strangely in the scene view
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
But in the game view
It will snap riding the place here this is just a way that unity allows us to edit text
Bobbing in the same scene It might feel really confusing it's just something you gotta get used to it
That's ok
I'm going to do is going to drag this text
All the way the top corner appear
We go
Take that ok
So pretty small so we need to be a little bit bigger so we're gonna make sure the text is selected
The font size here and we can make it like 35
You'll never say disappeared that's because it's bigger than the box it's surrounding the text so what you do is you just go to the rectal
Is drag a little bit bigger than it is right there
Ok cool
What's make sure this text is white
And if you go to our game window
Skragbad at MB bigger
Can you see the next year so this is going to be our coins
What's the better 0
Gregory about France right now is going to worry about the size you notice it keeps getting bigger and out of its box
That's ok I was just fixed the horizontal overflow to overflow
And in the overflow to overflow
Now it will show up regardless of the box size
But I like the box to be a Queen size 11 like it to be like this
I just look weird I like to be nice and clean
That I have an idea maybe how big it should be something like that so we can collect 10000 coins
It still fits in the box
That's great
So we have a coins here
And we want to test something
Burleigh ware 3840 x 2160
What will the text look like at 1920 by 1080
Stick-on Nancy
Wow
Disappeared
Why is that
Where's because
Noticed that the canvas is now a 1920 by 1080 the canvases automatically matching
Display size of the game so watch 3840 by 2160 scales up
Ok we can see
The text
But we got a 1920 by 1080 world
It's wrong
Now it's out of Bounce
What this is actually really easy to fix and this was way way harder to work with them
Scaling issues like this fixed
About 67 years ago when unity was using something called gygy elements as opposed to
UI elements which is a totally different system
The UI system
Unity users now
As opposed to 7 years ago when I started making games or even a decade ago
Didn't use a think I can do it so that click on the canvas and you'll see there's a canvas compony here
And is also a canvas scaler
What are we going to do is change this dropdown from constant pixel size
To scale with screen size ok
So far so good
And we want to have a reference resolution
We can make the reference resolution
The biggest screen size that were going to be building this game out which is 3840
2160
Perfect
And you can match the way to the heights I was going to scale based on the height or the width ok so we can do
Hi tour where to start a change much with this fine
You can expand you can shrink but for now it's going to worry about match with or height
Ok so let's test it out here and see what happens if you got 1821 1080
It's ok looks like resumed shrinkfast down there we go
3860 almost identical
That's great
What about
3 by 2
That's all weird
The nearest emergency are much bigger than they were
269
Pretty comb Argentina or summer colour padding
Pretty good Perry mirror but when we go to 4 by 3
Whoa what a padding there should be more snow up here
Why is that
Well we got a text
You can see that we have this
Lidl
Map
With God anchor preset and it's basically in forms
The object where it should be snug
In the canvas where should it be positioning
What currently is trying to position in the centre we don't want that
Wanted to be the top
Left hand corner
That's great
Circumcision nothing changed will it go back to 16 by 9
Or was better yet let's go back to 3840 x 2160
Ok
That looks like
We need a move it back
Where was salicea
Right up here just like that
Now
Because we changed
Encopresis to be the top left
Can we position it we want it
Now and we got a 4 by 3
Nice and snug no matter what kind of aspect ratio in you see if you look with your free aspect
It's nice and snuggle that tablet in corner
With equal padding
Or March
I will keep it in 1925
That was awesome
So there is our coins ok
Now it's update for coins with the collectible script
Collectible
In open up Visual Studio here
Collectible script basically we want to add the coins collected which we have done
We want to destroy a gameobject which we also want to do but before we destroy a gameobject what we also
Do is
Update
UI
We want you are
Update
In show how many coins we've collected
Well I don't really want to do this inside of the collectible script
The reason why is because we can't sell we will need to find
You are right
So I can do game object find
Coins UI
Dart
Get component and get the component which is the actual text right
And then you'd have to go that text equals
Whenever are coins collect it is right
Coins collected
This is going to be a real pain we don't want to have to do this over and over and over especially for updating various UI element
We actually rather have a function inside of new player
We could reference by multiple game objects ok
2 years old going to create a new function
Update
UI
Elements
Now technically wiki create a new class or script called you why and how it update their but I'm
Having it in the new player script
I'm going to go to call this public void
Update UI
Erika
Ok
So we're going to need a reference
To the coins you are
How we gonna do that
The pseudocode would be
Coins UI
Text equals
Coins collected
Ok
What is the coins UI
Well right here you see we need a reference to coins you why
Where we do that if we go up here for a variables to create a new variable and believe it or not
Instead of floating images in bullions in strings
You can also create a variable that is a reference to a component
So let's go back in the unity here
Take a look at the component
It is on this text item
Ok so we selected our coins text and let's be should a name it
Coins
Select that
Looks like we have a UI element called text
We want to reference that text we can actually create a variable in r script that is going to Forever reference
That coins text
To recreate a public
Text
Reference here
I'm really cold this coins text
So we can have integers floats we can have strings brilliant does it all lowercase
The moment you reference a component
Can be capitalised
This is public text
Coins text
All this is a reference
Do the coins text
So we can reference this in multiple ways right now he has no idea
Rich text item in it is only knows that were trying to reference a text component
You could have 1000 text components inside of your Unity Project
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
To which text component are we referencing
Well there's two ways to do this
The first way would be to go into the start function in before any of the Script run
We can find that
So we can go
Coins text
Equals
Game object
That's fine
What's your name
Coins
Getcomponent
Text
Remember the syntax for
Find is a little bit different than getcomponent
The name of the game object in princesses and inside of quotes but forget component you can put it inside of you
Brackets here
Text
And then you follow with princesses
Honestly and I can't get into my bed is just know that Dad's tax
That's one way if we do debug.log
Text
Go on unity
Play
And hopefully in the console window it's going to print out exactly what it is
Ok there is right there
Remember we have one
I'm emo debug.log happening here
And that's in the collectible Script so you don't need to worry about that
Direct here below the I'm mod bug that We Created earlier you can see this new debug.log
It says coins and then it a unity UI text component
Looks like we have a reference
Lower pseudocode here we can say coins text equals
Well what do you want to be
Coins collected
Ok so looks like we have a red squiggly line here
Why is that
Well when you're trying to make it something equals something else they need to match in their variable
Type ok so what is the variable Type 4 coins text
What we scroll up you can see right next to it
It's not an integer
Where a string is actually a text component
That's the type of variable it is
Is a reference to a component
So we can make a component equal
In integer which is coins collected
We need to make sure
That were finding something inside of a component
That could be an integer
The what is that
Well if we type coins text Dad
We can go through a lot of different variables that are inside the component
We actually go to the components and take a look
It looks like we have a text field
Inside the text component
That could be an integer array
Does type in coins text
Text ok
Eagles coins collected
Well that still didn't work
Why is that
What's because the text field
Is not an integer
Is anything I can be anything I wanted to be right
It's a string
Meaning I could write Bob's your uncle
In this text field here
And they're 42 string right so we need to make sure that coins collected is not an integer
A string
We wouldn't want to change it here right I wouldn't want this to be a string
Because then it would be an integer so how do we solve this
What we know we want our coins collected to be an integer that's a given
So what we can do is actually convert
Coins collected
To a string so that I can fit inside a coins that tech
You all were doing is basically
Changing 10 coins
2
10
That's all were doing now we're not actually going to change the actual coins collected variable all
Doing a saying
Get the coin slot in variable and then change it
To a string just for us to actually store there
Inside of a coins text
Field
All we do is coins collected data to string
Here we go
Is it just a call a function that will take an integer
And say you know what I want this to be a string
That all it's doing right here
Tell
But it's saviour
And see if Artex box
Actually
Change it out
Let's put it 0 again this is not an integer right here
This is a string
Basically this
0
Let's just make this a 0 by default
And hopefully
And see what happens
Ok
Well nothing happened why is that will be good or player
We have one coin here but it's not updating here what's going on
Still not updating
What is going on
Well
The reason why it's not doing anything if we actually haven't even told uniti to fire this function or call
Dysfunction
We need actually have it because somewhere
Well we can call it here if we wanted to inside of a start
The moment that unity starts let's update the UI
It's Gonna Call
So what if we said
Coins
Collected equals 200 what we said that in the start function
And then we updated that you are
Technically it should buy this function in set the text to be we're going to collect it is so
Set a 200 so let's try that
Ok cool
Just send it to 200 so we know that the function actually works
Updating when we collect the coins
Well
That's because
We haven't actually fired it
When we collect it
Here
Inside of the collectible script
When we do the ontriggerenter
Ok so now we know that updating the UI and calling that
Definitely works
Because when we hit play
It's at the text
200
So good there
But we need to call the update UI function
From the collectible script
Remove this like quick
Yeah we don't need this debug anymore
My bills clean up this as well
Not need those comments
Collectible here alright
Stop
Update you I should occur somewhere around here
So we're going to be something similar to this line here we going to do game object
Find player remember that function the update you a function is inside of
Player
Getcomponent new player
So we're finding that component
And then we're going to fire the functions inside of their component this is the component right new player
Remember new player has this function in it called update why
Tell
Are we due
Is upday
UI
What's your brief overview before I hit play Alright
First
We're going to find the player
Well
Is the player
So this line literally just says hey unity find
A game object with the name player
There I am
Find the player gameobject
And then you say
In addition I want you to keep going inside of the player and I also want you to find the new player component
Attached
To the play a game of
Unity find the player and then he goes where is that component there it is
And it finds the new player compose
Attached the game
Do you start with a gameobject
You're looking around for the game object you find it
And then you find a component
And then you say
Find the variable inside of that component
Which is the coins collected variable here
And then increased by 1
Perfect
Unity increases by 1 and then it jumps to the next line here
What's find the player
Find a component
Cannot find the function and you always know something to function if it has an uppercase letter usually that's how functions are written
So is an uppercase
Update UI
It looks inside of the Script
Defines the function
In a fire is it
Voice text that text
Equal
Are coins collected
But remember we got to convert that integer to a string
Save it out and see what happens
Ok so we're one great
Do awesome 34 grey collecting coins have a game feels like a game now
Hardest setting for collecting things right
This is Arsenal works great
Is one thing that I want to do and that is clean up our scripts a little bit more so we're going to do that in the next video
So far things like pretty great
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.