All language subtitles for 5. Starting Player Position

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
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 are going to set a starting position for our player by creating our first see sharp

script that's going to define him.

That's going to define the characteristics and behavior of our player to do this.

We're gonna create a new scripts folder by right clicking the assets folder selecting create and we're

gonna create a new folder all of the scripts that are going to make up our video game are going to be

stored inside of the scripts folder with the scripts folder selected you can right click and go to create

and we're gonna create a new C sharp script.

If you're completely new to coding you are in good hands and we're going to be walking through everything

together as we always are going to be completing challenges that are going to help you become a self-learning

motivated individual that can actually program and solve problems on your own.

So to do this we're going to rename the file as player.

It's important that you rename it while it's highlighted or you'll need to adjust it later.

You need to make sure that the class name in the file name are exactly the same.

You'll see here that if I suck the player we can see a preview of the script right here in the inspector.

It's very important that the public class player the name player they're matches the file name.

If I were to create a new C sharp script and then I click off and I lose that highlighter ability and

then adjust it.

So for example if I were to name this to my custom scripts you'll notice here that inside the actual

class it says new behavior script and unity will actually give us an error when we try to use it.

You need to make sure that the class name in the file on a match.

It's a simple adjustment.

Once we're in the script but it's convenient to name it properly the first time.

So I'm going to just delete that script and let's double click our player script to open it in Visual

Studio.

So here we are in Visual Studio and you can see here that we have our public class player and then a

colon and then model behavior that colon stands for inherits or extends Model Behavior model behavior.

It's a unity specific term.

This is what actually allows us to drag and drop scripts or behaviors onto game objects to control that

and you'll be using model behaviors as well as custom classes which are just simple classes like this

throughout your coding days with unity.

Now with Unity model behavior gives us two functions out of the box you get.

Void Start and void Update and you'll see here that we have a couple of comments that can be created

with two slashes if you're completely new to coding.

Don't worry I promise by the end of this course you will be on your way to becoming a self-sufficient

software engineer so that you don't have to follow countless youtube tutorials to learn how to code.

Let's go over the quick scripting outline that you see here at the very top.

These are called name spaces.

We're not going to get too focused on name spaces throughout this course but just know that they act

as libraries that give you access to coding for example model behavior is specific to the using Unity

engine namespace.

If I remove this you'll see here that things turn white because it doesn't know what they are.

In order to use them on a behavior of unity we have to include the namespace or library using Unity

engine.

In order to gain access to that code library the next two names faces here or libraries to access code

or system that collections and system duck collections not generic.

These are part of the dot net framework that allow us to write some C sharp code a part of the using

Unity engine and model behavior is the void Start in void Update.

These are methods that are called automatically from Unity for example.

Void Start is called when you start the game in void Update is considered a game loop.

It typically runs about 60 frames per second on a typical computer and it runs every frame.

So that's where all of our logic and user input is going to go.

Now for this what do we want to do with our player.

This script is going to be attached the player and behave as the player and what we want to do right

now is basically when we start the game let's go ahead and give us a starting position.

So basically we're going to say take the current position and assign it a start position and let's say

the current position of our character right now is at negative two point six seven on the Y when we

start the game.

I want to snap the position to zero.

How can we do that.

And what you need to get familiar with in unity in programming in general is the concept of writing

out pseudocode.

In comments you'll see here that the task is to take the current position whatever it's at.

When we start the game and basically assign it a new position and we want to basically say new position

and assign it a 0 4 x 0 4 y and a 0 for Z.

So how do we do this in order to do this.

Unity works in a very hierarchal structure.

How do I get the current position.

Well let's look at the game object.

If I were to take the script and attach it to the game object by dropping it on the player in the hierarchy

or by just dragging it in the inspector here it gets added as a component.

And this is important.

Unity is a component based design which is why it's so user friendly.

I can simply just add behaviors to game objects.

Right now this script is attached to our player game object and if I wanted to get the position of the

player how do I do that.

I first have to access the transform component.

Then when someone the transform I can get the position rotation or scale.

So we just looked at the visual representation for editing to do and let's take a look at it through

code.

I need to get the current position.

Well I need to first access the transform of the object and then if I want the position we can use the

dot operator to go further in.

So I'm on the transform component dot position.

If I wanted the rotation it would be transform dot rotation.

Let's say I wanted the y value of the position.

If I look on the player I access the transform the position and then I can go further in.

So I could say X or Y and you'll see here that I can type transform dot rotation or transform dot position

dot y so you can see here that's very hierarchal.

It's what we want to do is take the current position and assign it a new position.

The way we do that is through the use of what's called a vector 3 a vector three is what defines all

position types of unity.

Anything that is going to involve positioning of an A game object or an object and unity is going to

be reassigned through what's called a vector 3 and it has to use the new keyword.

So here if I type transform dot position which gets the current position let's take a look at the tooltip

which you need to get in a habit of reading you'll see here that it's a vector three everything related

to position in rotation data and unity is going to use a vector three.

The next thing here is that it says get inset.

That means that I can get the position as well as set the position in order to set the position.

You use an equal sign to assign it in any time you're working with vector 3s you're always 100 percent

of the time going to use a new vector three to define a new position.

So here I'm taking the current position and I'm assigning it a new position by typing in New vector

3 and if I open a parentheses you'll see here that we have three overrides I can say new vector three

I like this I can specify an X and Y if we're in a 2D setting or I can create a new vector with given

x y and z components.

So here I want to say zero on the x zero on the y in zero on the Z.

Let's save this.

Hop back into unity.

Make sure that you attach the script to the game object and you'll see here that I'm currently going

to position myself at negative 2 and if I run the game we're going to snap to 0 0 0.

And there you go.

We created our first line of code which takes the current position and assigns it a new position.

You should be able to begin to imagine the scenarios where reassigning positions and video games can

be really handy.

Think of a teleportation system.

You walk into something and appear somewhere else.

All they're doing there is just reassigning the position and playing a particle effect to make it look

like you actually teleported somewhere where in reality you're just changing positions.

I'll see you in the next video.

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