Afrikaans
Akan
Albanian
Amharic
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
Russian
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
1 1
[MUSIC] 2
2
In this video, we're gonna give ourselves a way to have our waves loop over, and 3
3
over, and over. 4
4
So even if you have only two ways, and I'm gonna change my to two here, 5
5
it just goes wave one, wave two, wave one, wave two, over, and over, and over so 6
6
that our game can loop. 7
7
So we'll hop over into EnemeySpawner.cs, create ourselves a variable. 8
8
So we'll serialize this, so it's available in the inspector. 9
9
We're making a bool, so it's either gonna be either true or it's gonna be false and 10
10
we'll call it looping. 11
11
So I have a bool called looping, which we will initialize as false. 12
12
So bool looping = false;. 13
13
And then within our start method here's something really cool. 14
14
We're we can say we can change the type of return value for our start method. 15
15
So that when the engine calls start, it is doing something a little bit different, 16
16
we can change it to an IEnumerator, 17
17
so that we make our start a code routine, which is really nifty. 18
18
And then within our StartCoroutine, 19
19
just gonna put my curly braces down a line here. 20
20
So within our StartCoroutine we can create a do while loop, 21
21
which basically means it goes over and over and over at do while. 22
22
And we'll make it while looping is true. 23
23
So we'll give ourselves a little bit of room here and start by typing do. 24
24
And then give ourselves a code block in here of curly braces. 25
25
We're going to change our stock StockCoroutines inot our yield conditions. 26
26
So yield return StartCoroutine SpawnAllWaves. 27
27
So this now becomes the yield condition. 28
28
Once we get into the do while loop, we're saying do a thing, go, go, go, go, go. 29
29
And then, once it's finished doing all this, 30
30
the yield will then return back within our start method. 31
31
And we can say, close our, curly braces here, so we've got our yield condition. 32
32
And then we can say, While (looping). 33
33
And this is another way of saying While (looping) equals true. 34
34
We can say while, and then in brackets, looping. 35
35
So what we're doing here is saying when the engine call start, do this thing, 36
36
start the co-routines. 37
37
This is a series co-routine. 38
38
And we are gonna yield. 39
39
So come back to start and 40
40
continue with whatever is after this statement once this has completed. 41
41
So once this completed, we come back here. 42
42
We see the while. 43
43
If looping is true, then it jumps back up to the do and 44
44
it starts this all over again. 45
45
And because it started as part of the yield, then it waits until it's finished, 46
46
then it comes back to the while. 47
47
So this is a really neat loop and 48
48
a really neat way of saying we can do this particular thing here, this SpawnAllWaves, 49
49
we can do it over, and over, and over, so we can loop it in there. 50
50
So we'll save this up and hop over into Unity, check that it all worked. 51
51
The first thing we need to do is click On for Looping. 52
52
So let's check it without looping on, and make sure it's working as we're expecting. 53
53
You might wanna stop at the end of a number of waves, and 54
54
then the player can go on to another level, so you don't want it to loop. 55
55
Okay, that's it without looping. 56
56
We'll click Looping On, click on Play, and 57
57
we should see these waves looped over and over. 58
58
Okay, once, twice, okay, so you can see, they just keep getting spawned, 59
59
and spawned, and spawned. 60
60
And so you can imagine, this is a game, if we're spawning all these waves, and 61
61
the game is just going on and on, 62
62
you don't have to have to have created 300 different waves. 63
63
You can create a certain number 10 or 20 or 30 and the game will go on and 64
64
on forever. 65
65
And if you make your enemies engaging, if you make your waves interesting and 66
66
all that kind of good stuff then the player is gonna feel like this is 67
67
a pretty awesome game to play for a bunch of time. 68
68
Okay, so it's just a quick lecture on the do while loop and 69
69
how we have used that within our co-routine and how we have changed our 70
70
Start method to be an IEnumerator so that we can use it as a co-routine. 71
71
Great work, well done, I'm sure you're game is shaping up really nicely. 72
72
I look forward you seeing your sharing in the community. 73
73
If you've got something neat that you're enjoying with your waves, 74
74
then please do share it with us, and I'll see you in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.