All language subtitles for 8. Import & Refactor Code

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 be refactoring our code will be importing the previous number Wizards script

that we created in the number was a console section and doing a little bit of analysis of what we need

to change and then doing our first refactor of this code so it's ready to be used with our user interface.

So let's jump in and do some refactoring.

Okeydokey first thing we need to do is grab the previous code.

Our number is a code that we worked on from the no wizard console section of the Course.

If you don't have access to that then you can download the file that I've attached to this lecture number

was a dot C S drag that into your.

Scripts folder X or want a next thing to do is to create a game object so we can attach our script to

that game object right click in the hierarchy create empty we'll rename this to game play.

And as good practice we reset the transform.

Now we can drag our number was a script.

As a component on to our game play game object that means that when we run the game the script the script

will be run.

Let's open up number wizard and have a look and see refamiliarize ourselves with the old familiar Coale

code from a couple of sections ago.

Okay we've got some variables we're declaring up at the top here.

We created a stack game method where we're giving the player a whole bunch of here's how you play the

game information and then in our update method we've got our player input where we're using our if and

else if statements to see whether the player has pushed up or down or return and get key down was the

mechanism we're using in there for the players input.

Let's have a little look at what we need to do refactor what I'd like to do is serialise our variables

at the top so that we can change them in the inspector and not have them hard coded into our code here.

Need a removal of our debug information and then change the the player input.

So instead of using our get keyed down our keyboard input we need to create public methods similar to

that which we did in Scene lodo where we had public void load next scene so that we can create public

methods in here that we call from our button presses so those are the three main chunks serializing

removing the debug and changing the player input that we need to do.

And when I say we of course I mean you know what I'd like for you to do as a challenge is to start refactoring

your code serialise field for the minimax variables to remove the debug dialogue text that we don't

require.

And instead of IF statements in Update create two public methods and we'll call them on press higher

and on press lower.

So those are the steps.

The Challenge You should have everything you need to jump in and give that your best shot and when you're

ready I'll see you back here and we'll go through the solution together.

Radio first step is to serialize our variables so serialise field for Max and.

Serialise field for me.

I'll save that just check that that has worked.

Jim back over in here.

Click on game play.

After it compiles click on game.

That we go.

And you can see there is a max an image in here that we could set to say one thousand and one.

Next steps I'll just delete my debug text book.

Get rid of all that.

Anywhere we see debug just gone.

And also within the next guest's method.

So all of that has now been gone.

Excellent.

Next it was the next part of the challenge was to create the public methods on press higher and on press

lower.

So we'll do that right above where we currently have.

Update we'll be delaying all of our update the moment but for now we will start by creating public void

on Press.

Hi.

Parentheses and then our curly braces.

We need to do exactly the same logic that we're doing when we push up arrow so I will grab the mean

equals guess and next guess method.

Copy that pasted inside my own press higher method here.

Great.

Second we need to go public void on press low so be our other method again.

Kelly bracers.

Where is their logic it Max equals guess.

Next guest.

Copy that.

Paste it within here.

That looks pretty good.

We don't need to have anything for our.

Did you get it correct because we already have connected to our success button here.

It calls the load next scenes that's taken care of.

Which means we can delete all of our update method and everything that is contained within it.

So now we just have all variables being declared at the top level of logic we need to tidy up in start

game and our next guess ops.

I accidentally deleted an cares to do that don't delete.

Next guess again.

So just delete what is an update.

There we go.

Thank you Red squiggly line for letting me know I had done something foolish.

OK so on press higher on press lower and next guess we still have they will save that.

Now let's have a look at what's going on in start game.

Just here we've got our Max equals Max plus one.

That was our mechanism for making sure that we absolutely can get to a guess of 1000 because of rounding.

We say Macs Plus mean divided by two.

Then we didn't end up getting to a thousand or was 999 as high as we could get to.

I'm going to move that up to the top.

They are Macs equals Macs plus 1 so we can establish them straight away and then we don't need to be

re assigning max and min.

We also don't need to have Guess haeckel's 500 that's hard coded in there.

Got a whole ton of lines in here for some reason now what we do need to do next is have some sort of

guess so what is our guest going to be.

Well guess as we have done here is Max plus min divided by two.

Copy that line within our next guess and put it in start game so that as we did before were establishing

Let's have a guess right at the start.

But we don't hardcoded it because up here we might say that the max E is out ten thousand or twenty

three whatever we want to sit now inspector now is vector over here whatever we are assigning as the

max and the main.

So then we need to have our calculation based on the variable Max and the variable min right here in

our start game method I get so on start with Call start game.

Excellent with tidy that up.

We have on press higher on press lower and next guess.

Excellent so we've tidied up all our code in here is looking pretty good.

The one last step that we have to do is to display onto the screen what our guess actually is and that's

going to be the topic for the next lecture where we're looking at the two string function and hooking

up all of our text field so great work with your Reflektor great work in this video.

We're getting very close to finishing up our functionality I think in the very next lecture will have

it so that we can play our game the whole way through so great work and see you again very shortly.

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