All language subtitles for 8. Speed Variable

af Afrikaans
ak Akan
sq Albanian
am Amharic
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
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

In this video we're going to take a look at variables throughout this course we'll be covering the complete

fundamentals of C sharp programming.

I'll be working the concepts in as we go.

But if you'd like to master the concepts beforehand or get more experience with C sharp in unity I would

highly encourage you to grab a copy of the unity C sharp Survival Guide.

It's another course created in partnership with Unity Technologies and it's designed to prepare you

for a career with C sharp in unity.

It's a great compliment to this course and any other course you're taking on udemy so let's take a look

at variables.

Variables can be thought of as a box that has information in it and that box of information can change.

It's called a very which means the data can vary it can change the variable.

So an example here is that we could have a speed variable and the reason that we'd want a speed variable

is does it make sense to change this hardcoded value every time.

If I suddenly want to change it so that my player moves 20 meters per second and then later I decide

that I want to go to two meters per second.

Does it make sense to always come back here and update this hardcoded value.

Absolutely not.

So what we can do is we can introduce the concept of variables which will allow us to adjust this value

based on whatever the variable is at the current time.

So to create a variable there are three required components with an optional fourth.

The first component here is a public or private reference.

This variable can either be public or private.

If it's public it means that the outside world can communicate with that variable.

Other scripts and other game objects can know that variable exists.

If it's private only the player knows that variable exists.

The next part is the data type.

Every variable has a data type.

There are four common data types in C sharp.

They're ints which are whole numbers floats which are decimal values billions B O L which stands for

bool.

These are true or false values and then we have string in strings or characters of text.

This is basically saying what type of variable you're creating.

So for a speed variable we could use an integer value or a fluke value.

If I want to be able to go 5.5 meters per second I have to use a float.

If I want to go five meters per second I'll use it for my name.

It's going to be a string of text so I'm going to use a string for a ball that says if I'm awesome or

not it's a true or false question.

I'm going to use a ball.

The next thing here.

That's the third requirements and final requirement is every variable has a name without a name.

How do I know what I'm talking about.

Every variable has a name it could be whatever you want but it has a name the optional fourth is a value

assigned optional value assigned so let's take a look here at declaring a variable for a speed and let's

say here that I wanted to support float values I could create a public float for my data type and then

a variable name.

Public floats.

Let's go ahead and say speed and I could leave it like this with a semicolon and it has a default value

of 0 or optionally I could assign it to let's say three point five f the F suffix stands for float.

If you forget the F unity won't compile and it will actually tell you that you have an error you'll

see here that you have some red squiggles resolve it with the suffix.

If I was doing an integer value I could simply just type three and you'll see here it's three point

five giving me red squiggles because it's a float value not an integer value.

So right now I'm setting it to three point five.

F I change the int to a float type and then to actually make use of this variable I just replace the

two with my speed.

So I'm multiplying it by speed.

So speed currently is three point five.

So when we run this line of code it's going to take the value of three point five.

If I save this and hop back into unity you're going to see something pretty cool in unity when you're

working with public variables.

You can see them as well as adjust them in the inspector and what's important to note here is that the

Inspector will override what's in the script in the script this has three point eight or three point

five.

But in my speed in the inspector here it says 10.

So what's going to happen here is we're now going to move 10 meters per second to the left.

And the reason why we're moving left is because I have vector 3 not left.

If I change this to vector three right and save this you'll notice here it still says three point five

f we're going to move 10 meters to the right so if I play it again you'll see here that we're moving

10 meters to the right.

And if I wanted to I could even slow it down a bit more let's say here one point five and what's even

greater is that you can manipulate this value in real time.

Right now I'm moving one point five.

I can speed it up and if I go reverse a negative value we're now going to the left.

So what we're going to do now is map this to user input in the coming videos

if I wanted to have these script value overwrite what's in the inspector here.

I can do that by resetting the script.

There's a gear icon and I choose reset and it will now set it back to three point five.

But as soon as I change it in the inspector the inspector value is going to override what's in the script.

Now that's a public variable.

What happens if I make this private I'm going to save this.

Hop back into unity.

Unity is going to compile and you'll see here that our variable is gone.

If I run the application we still move three point five meters per second to the right but I can't adjust

the value anymore.

And that's because it's a private variable.

Only the player can access it and change the value if it's public.

It means other game objects can potentially manipulate it.

For example in Mario Kart when you collect a power up in it adjust your speed it changes the value because

it's a public variable something to note here that's kind of a best practice to do is to determine early

on whether or not these should be public or private variables.

If it's a private variable you'll typically see an underscore which is a dot net standard for the variable.

The reason we use an underscoring the name here for private variables is so that when you're let's say

hundreds or thousands of lines deep inside of your code you can look at a variable and know that it's

a private variable based on the underscore going forward.

Most of our variables are going to be private unless we see a need for it to be public.

If we need another script to directly modify this value we'll keep it public.

But if we don't see a need for the most part best practices everything should be private.

Last but not least let's say here that I want to keep it private but I want my designers to play around

with the speed and not have to open up the script and change this value every time.

Well we have a solution and that solution is the concept of an attribute.

We can add an attribute above a variable of type serialized field and what that's going to do is serialize

the data so that we can read it in the inspector and not only read it but overwrite it from the inspector.

So you'll see here that our speed variable is back even though it's private.

And if I run the application I can still control the speed values.

So my designers can come into the game and modify the values.

However other game objects and scripts can't touch the value as intended.

So that wraps up some variables for some practice.

Check out the unity see shops survival guide which is filled with tons of challenges on making you a

master at all things C sharp.

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