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
Alright so some of you then probably wondering
Thomas why are you not using the Singleton pattern
Now some of you are thinking what the heck is a Singleton pattern
Well let's jump into you
Are collectible script here
Take a look at something
We have a new player variable to that we actually have a reference to the new player component
Welsh Everytime We create a script correctly
We have to create a new reference
To the new player
Frustrating
We do that again as well so
A magical find player that getcomponent new player
This is redundancy in Multiple scripts
It's kind of annoying
If we had an enemy scratch
We also have to write this out in that
If we had an NPC script
Subtitled by -♪ online-courses.club ♪- We compress knowledge for you! https://t.me/joinchat/ailxpXoW3JVjYzQ1
We have to write it out there
We been writing it out probably 100 to 200 times for a final game and I can actually admit that
Striped my very first game
Does this
The alternative is to use something called a Singleton
A Singleton basically refers to a game object that is easily reachable from
Anywhere in there only exists one of these
At any given time to have more or less than one of these game objects
Set a player game object with the new player component
Is actually a Prayer example
Have a Singleton
Because it's only ever one thing in the entire game
You never going to have multiple players
Right
So if I want any script that I create
To be able to reference this player
Whenever I want without requiring me right out this
Horrible
Line of code gameobject find player that pony
If I want to avoid writing this all the time
Then what I need to do
Is simply
Make this new player
A Singleton instance
It sounds confusing
The words are kind of strange
And when you look at the code it's going to be even stranger and trust me and strange to me too
Actually haven't even memorise this code and the reason I haven't memorised it is
Well to Singleton you only use it once you write this code once
Any allows you to do so much
For your entire game
Oh really you're probably only going to write this line of code that were about 2
Once or maybe twice in your game
Maybe you have a Singleton for the player
Maybe you have a single team for something that people called a Game manager which one are actually going to create for this demo
Set another place where you might use the Singleton instance
So we're going in stage you are single
Are we going to do is just go to the
Bottom of a variable seer before start
Let's just make sure we come in today
Singleton
Institution and if this doesn't make sense guys when we start using it
It's going to make a lot of sense
Private
Static
Can you play not gonna get into what static is because honestly we're only reading this line of code
The seriously has just right this code trust me I'm looking at universe documentation right now
Has arrived this
New player instance
Brackets
Get
There we go and then we're going to create a simple condition
If the Instance is nothing
It's no
Instance = game object
That find object of type
New player
NN return instance
Thomas what the heck did you just right and I'm going to be honest with the guys I say this all the time I don't know
But I know what it does and I know when I need to use
And I can't see this enough
As a game developer is not necessarily about understanding every navygrey detail about your code
Understanding what everything means and memorising
Is really about knowing ok there's this thing called singleton's ok and he is a Singleton let's Google that
Now if we're in the apocalypse so we didn't have Google
I would not be a game developer I wouldn't know what the heck I'm doing and I think a lot of Jayne developers wouldn't either
But in this case
Does just know singleton's are used
A single object like a player
Are you going to be referencing all over the place in various scripts
So now we have this line of code that we just wrote
How to reference the new player
Whenever we w ok
What's going to a collectible here in Trail
We don't actually need this anymore
Remove that
We can remove this
But we got a little here here
How do we fix this
Now that we have the Singleton
Would you actually write
New player
Instance
So because we only have one single instance of the player in the entire game
Description girl ok well where can I find that object type
New player
Where to find the Instance
And we're going to do something with it
So we can just literally
Is that all over the place
Get rid of those double dad's there
As well
Say that
I'm your reference at all we didn't need to write anything up here to reference and find that game on
We can do the same thing in the gate to look
Remove all of this Ray and just do you play it at instant start inventory
Even better
Instead of
Game object at nibbles player
What if we just said 8 collision that game Argos
Equals
New player
That instance
That game are checked
Coda cleaner
Actually I like cleaner in the long run because we have a lot of scripts doing this
Does going to Unity in make sure that my instance
Actually works
Now if the code works properly nothing is going to change
Looks like everything works great
Nothing changed
But a lot change
For us as the developer
Because now we don't need to use gameobject that finds I get component blah blah blah
We can do simple use
New player
That instance
And that my friends is the Singleton instantiation
And that's all because we wrote the single line of code up here
Decorated this instance for the new player
And it's weird
I'll be honest it looks weird
Is amazing what you can accomplish
And again guys it's not about understand me every freaking thing about your code
Is that about understanding
How you can memorise all of this code it's about understanding the simplistic terminology
Are you going to remember if there's this thing called a Singleton Thomas was talking about it
What was the my Google it there it is this is the code
How to write a Singleton pattern
How many use that from a player
Or I'm gonna use that for my
Email address which stores you know in Victoria something
That is a Singleton you're going to use it he once or twice in your indie game
And then we'll never going to write this code again guys so I'm not going to memorise it
We need to go into our collectible script and just make sure that now they were using
An instance of new player
We need to make sure that we changed this out as well so instead of checking the name
I don't want to check the gameobject it says
Is collision tag a mate
Equals
New player
The Instance
Game on
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.