All language subtitles for 29. Set & Place Selected Defender

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:00,000 --> 00:00:03,930 [MUSIC] 2 2 00:00:03,930 --> 00:00:07,580 Hello, again in this video, we're gonna be able to click on our defenders and 3 3 00:00:07,580 --> 00:00:10,750 place down different defenders where we want them to be on the grid. 4 4 00:00:10,750 --> 00:00:12,840 So, let's jump in and get started. 5 5 00:00:12,840 --> 00:00:16,160 Let's start by taking a look at the scripts that we'll be using in the next 6 6 00:00:16,160 --> 00:00:19,380 few videos, and the scripts we need to make everything work. 7 7 00:00:19,380 --> 00:00:23,650 We need a Defender Spawner, Star Display, Defender, and Defender Button. 8 8 00:00:23,650 --> 00:00:25,610 The Defender Spawner is gonna be responsible for 9 9 00:00:25,610 --> 00:00:28,840 storing whoever the defender is that is being selected. 10 10 00:00:28,840 --> 00:00:30,330 So whoever is being clicked on, 11 11 00:00:30,330 --> 00:00:33,400 we need to find the cost through the Defender Spawner. 12 12 00:00:33,400 --> 00:00:35,810 Find if we have enough stars. 13 13 00:00:35,810 --> 00:00:38,060 So we need to make sure that if the bank is empty, 14 14 00:00:38,060 --> 00:00:40,340 we don't let people place down a defender. 15 15 00:00:40,340 --> 00:00:42,630 We need to tell the stars to be spent. 16 16 00:00:42,630 --> 00:00:47,020 So over in our Star Display, we haven't created yet, but we will create a script 17 17 00:00:47,020 --> 00:00:50,870 that will allow us to have a reference for what the current resources are. 18 18 00:00:50,870 --> 00:00:54,410 How many money you have in the bank, and then to answer the question of do you have 19 19 00:00:54,410 --> 00:00:59,300 enough stars to buy a particular defender and to spend the stars,. 20 20 00:00:59,300 --> 00:01:02,260 So therefore to decrease the number of resources 21 21 00:01:02,260 --> 00:01:06,810 as well as increasing spend stars and increase stars. 22 22 00:01:06,810 --> 00:01:09,640 And then we need a Defender script and that's gonna provide the cost. 23 23 00:01:09,640 --> 00:01:14,140 So a cactus costs this amount and a trophy costs that amount, for example. 24 24 00:01:14,140 --> 00:01:16,240 And then the Defender Button, which we've been working on. 25 25 00:01:16,240 --> 00:01:20,340 This is where we're setting the defender prefab, so when you click the button, 26 26 00:01:20,340 --> 00:01:23,610 it says, this particular defender is the defender. 27 27 00:01:23,610 --> 00:01:26,130 That's who we're interested in as their prefab. 28 28 00:01:26,130 --> 00:01:29,550 Next up, what I'm wanna do is create a script that says, you're a defender. 29 29 00:01:29,550 --> 00:01:34,070 So, right click Create > C# script, which we will call Defender. 30 30 00:01:34,070 --> 00:01:37,910 We're not going to do a lot in this script just yet, but I want to have it around. 31 31 00:01:37,910 --> 00:01:41,470 So, double click to open up in Visual Studio, I wanna have it around so 32 32 00:01:41,470 --> 00:01:45,462 that I can be tagging things as type Defender as well. 33 33 00:01:45,462 --> 00:01:48,570 That's gonna be very useful, so we're being specific with the type. 34 34 00:01:48,570 --> 00:01:50,850 So, in here, what you will do is straight out, what? 35 35 00:01:50,850 --> 00:01:55,800 Pretty simple, we're just going to start by getting rid of our Start and 36 36 00:01:55,800 --> 00:01:57,880 Update methods, don't need those. 37 37 00:01:57,880 --> 00:02:01,214 I'll create a SerializedField, really simply, 38 38 00:02:01,214 --> 00:02:03,860 integer and we'll call this starCost. 39 39 00:02:03,860 --> 00:02:07,932 Star is the currency that I'm using, so you could be coins or moolah or 40 40 00:02:07,932 --> 00:02:09,943 schmeckles, whatever you want. 41 41 00:02:09,943 --> 00:02:13,150 StarCost = 100 is how I'll start that off. 42 42 00:02:13,150 --> 00:02:18,070 So that means for each defender we can say how many stars they cost. 43 43 00:02:18,070 --> 00:02:18,730 We'll go back over, 44 44 00:02:18,730 --> 00:02:23,880 we'll find our trophy and drag our Defender script onto the trophy. 45 45 00:02:23,880 --> 00:02:26,270 At the parent level, same with the cactus, 46 46 00:02:26,270 --> 00:02:30,300 drag our Defender script on to the parent level of the cactus, okay. 47 47 00:02:30,300 --> 00:02:33,350 So these are now defenders through the night for 48 48 00:02:33,350 --> 00:02:36,680 the fact that they have to Defender class or Defender script sitting on them. 49 49 00:02:36,680 --> 00:02:39,680 Next we're gonna jump into the Defender Button script and 50 50 00:02:39,680 --> 00:02:41,270 do a little bit of work in here. 51 51 00:02:41,270 --> 00:02:43,750 First thing we need to do is create a notion of who is 52 52 00:02:43,750 --> 00:02:45,640 the prefab you have selected. 53 53 00:02:45,640 --> 00:02:50,459 At the moment we've got cactus and trophy, but we need to serializeField and 54 54 00:02:50,459 --> 00:02:54,912 then I'll type Defender and that will complete because we've gone and 55 55 00:02:54,912 --> 00:02:58,992 created type Defender just now with our class, with our script, 56 56 00:02:58,992 --> 00:03:02,141 and we will call this defenderPrefab semicolon. 57 57 00:03:02,141 --> 00:03:06,430 Save that, now let's go into our buttons and assign that straight away. 58 58 00:03:06,430 --> 00:03:10,980 So find Button > Background > cactus. 59 59 00:03:10,980 --> 00:03:16,403 Now the Cactus has a defender prefab, let's click on that there and 60 60 00:03:16,403 --> 00:03:22,609 we will assign cactus and then trophy and we will assign trophy, there we go. 61 61 00:03:22,609 --> 00:03:23,182 Okay, so 62 62 00:03:23,182 --> 00:03:27,862 we've linked the button to the particular prefab that we have in our folder. 63 63 00:03:27,862 --> 00:03:31,390 Okay, so save that, that's all looking pretty good, what next? 64 64 00:03:31,390 --> 00:03:35,410 Well, let's jump over to the DefenderSpawner script, and 65 65 00:03:35,410 --> 00:03:36,250 see what's going on in here. 66 66 00:03:36,250 --> 00:03:38,830 First of all, we've got this notion of, previously, 67 67 00:03:38,830 --> 00:03:41,950 we didn't have a Defender type, so we're calling things GameObject. 68 68 00:03:41,950 --> 00:03:43,450 Let's go and change that, so 69 69 00:03:43,450 --> 00:03:46,120 that they're all Defender where we're referring to defender. 70 70 00:03:46,120 --> 00:03:48,900 So this will be defender defender and 71 71 00:03:48,900 --> 00:03:52,180 also we don't need the serialized field anymore on the DefenderSpawner 72 72 00:03:52,180 --> 00:03:55,950 because that is being determined by what is being clicked on on the buttons. 73 73 00:03:55,950 --> 00:03:59,070 So we're not gonna let the designer go and monkey around that. 74 74 00:03:59,070 --> 00:04:00,960 We'll get rid of the serialized field. 75 75 00:04:00,960 --> 00:04:05,360 It's just now defender defender, where else is that gonna be relevant? 76 76 00:04:05,360 --> 00:04:07,250 Well, let's see where defender is being called. 77 77 00:04:07,250 --> 00:04:09,160 And you see we've got the red squiggly line down here, 78 78 00:04:09,160 --> 00:04:13,080 it's saying I'm not a game object anymore, I am a defender. 79 79 00:04:13,080 --> 00:04:15,001 So defender instantiate, 80 80 00:04:15,001 --> 00:04:19,768 [SOUND] as defender much more specific than just saying GameObject. 81 81 00:04:19,768 --> 00:04:21,200 Okay, it looks pretty good and 82 82 00:04:21,200 --> 00:04:24,730 I think we're referring to game object anywhere else, good. 83 83 00:04:24,730 --> 00:04:29,680 Next we need a way of creating a public method within the DefenderSpawner, 84 84 00:04:29,680 --> 00:04:33,260 we say this is who should be selected. 85 85 00:04:33,260 --> 00:04:36,310 And then within the DefenderButton, we could then say hey, 86 86 00:04:36,310 --> 00:04:40,720 I will to select my particular defender at the thing you should spawn. 87 87 00:04:40,720 --> 00:04:44,300 So start with the public method in, DefenderSpawner. 88 88 00:04:44,300 --> 00:04:50,791 So I'll say public void SetSelectedDefender and 89 89 00:04:50,791 --> 00:04:56,054 then we need to pass in of type Defender. 90 90 00:04:56,054 --> 00:05:00,430 And we'll call this defenderToSelect. 91 91 00:05:00,430 --> 00:05:03,750 That's the one that somewhere else is saying, hey select me and 92 92 00:05:03,750 --> 00:05:05,220 then we have our parentheses. 93 93 00:05:05,220 --> 00:05:09,350 Now what I'd like for you to do in here is to just finish off as a little challenge. 94 94 00:05:09,350 --> 00:05:15,210 Finish off to assign the passed in defender as the current defender. 95 95 00:05:15,210 --> 00:05:20,360 So we're pasing in this defenderToSelect, which will be called in DefenderButton. 96 96 00:05:20,360 --> 00:05:25,040 We'll say, okay, give us the defender and then we want to assign that to 97 97 00:05:25,040 --> 00:05:29,640 the current defender, so pretty simple just two words and one equal sign. 98 98 00:05:29,640 --> 00:05:33,324 There's a big hint for you, so just finish that for me now if you will. 99 99 00:05:33,324 --> 00:05:37,527 Okay, straightforward so 100 100 00:05:37,527 --> 00:05:42,730 defender = defenderToSelect. 101 101 00:05:42,730 --> 00:05:47,660 So, the thing that's getting passed in is now being assigned to defender and 102 102 00:05:47,660 --> 00:05:48,650 we'll save that. 103 103 00:05:48,650 --> 00:05:51,060 Last step in this process, back to DefenderButton. 104 104 00:05:51,060 --> 00:05:53,820 We need somewhere in here that we say, okay, 105 105 00:05:53,820 --> 00:05:57,600 I would now like to tell everybody who to spawn. 106 106 00:05:57,600 --> 00:05:58,810 Who is the selected defender. 107 107 00:05:58,810 --> 00:06:02,750 So on the OnMouseDown method right there the very bottom, 108 108 00:06:02,750 --> 00:06:06,590 underneath GetComponentSpriteRenderer where we're changing the color to white, 109 109 00:06:06,590 --> 00:06:09,720 we're gonna be calling our SetSelectedDefender. 110 110 00:06:09,720 --> 00:06:14,690 So first of all we need to FindObjectOfType and the type is what? 111 111 00:06:14,690 --> 00:06:16,400 It is DefenderSpawner. 112 112 00:06:17,890 --> 00:06:23,890 That's where we've created our public method .SetSelectedDefender. 113 113 00:06:23,890 --> 00:06:27,111 Now, we need to pass something in, what are we gonna pass in from here? 114 114 00:06:27,111 --> 00:06:29,820 Well, pretty straightforward, we're gonna pass in the defenderPrefab. 115 115 00:06:29,820 --> 00:06:32,890 So we know who the defenderPrefab is, if this is on the cactus, 116 116 00:06:32,890 --> 00:06:34,700 the defenderPrefab is the cactus. 117 117 00:06:34,700 --> 00:06:39,650 So defenderPrefab in here, excellent! 118 118 00:06:39,650 --> 00:06:43,020 When that's called that will pass it in, so we know what to spawn. 119 119 00:06:43,020 --> 00:06:47,060 Now save everything up, if that's all gone to plan when we click on Play, 120 120 00:06:47,060 --> 00:06:50,550 we should be able to select the cactus which has been what we've spawning up 121 121 00:06:50,550 --> 00:06:54,420 until now, works, and the trophy, and it works! 122 122 00:06:54,420 --> 00:06:59,210 Nice and lovely, now one thing you might have noticed is the trophy 123 123 00:06:59,210 --> 00:07:01,870 looks a little bit weird, a little bit strange, it's not in the right spot. 124 124 00:07:01,870 --> 00:07:05,450 So let's fix that, first of all, now click on trophy, 125 125 00:07:05,450 --> 00:07:08,740 my one trophy that I've got in my world here, have a look at it. 126 126 00:07:08,740 --> 00:07:13,840 Okay, it looks like when we place it, there's a bit of an offset, so if I have 127 127 00:07:13,840 --> 00:07:19,230 this at exactly four and four, you can see that it's a little bit too high. 128 128 00:07:19,230 --> 00:07:22,380 So our child object a little bit too high. 129 129 00:07:22,380 --> 00:07:24,300 Now, here's a really interesting thing, 130 130 00:07:24,300 --> 00:07:27,770 really interesting problem that we can create for ourselves with animation 131 131 00:07:27,770 --> 00:07:32,640 is that when I click on base, I can move the base up and down, no problem. 132 132 00:07:32,640 --> 00:07:33,860 I can move it right down and 133 133 00:07:33,860 --> 00:07:37,100 say yeah that's exactly where I want the base of my trophy to be. 134 134 00:07:37,100 --> 00:07:39,290 Now if I click on the top and 135 135 00:07:39,290 --> 00:07:42,080 move it down, yeah that's exactly where I want it to be. 136 136 00:07:42,080 --> 00:07:43,590 Watch what happens when I click play. 137 137 00:07:47,284 --> 00:07:50,590 The top of the trophy's gone back up again. 138 138 00:07:50,590 --> 00:07:53,170 So to make that even clearer, if I was to drag that way, way, way, way, 139 139 00:07:53,170 --> 00:07:55,470 way down here, and I've clicked on the top. 140 140 00:07:55,470 --> 00:07:58,400 I select the trophy bounce animation in the animation window. 141 141 00:07:58,400 --> 00:08:03,566 And scroll through that see it immediately goes blink run up here already, 142 142 00:08:03,566 --> 00:08:08,486 [SOUND] straight away because the rotation we've got in here is relative 143 143 00:08:08,486 --> 00:08:09,966 to the bases itself. 144 144 00:08:09,966 --> 00:08:13,665 It's not saying go to a particular coordinates, so you look at the base you 145 145 00:08:13,665 --> 00:08:17,660 can drill into it here so we've got rotation, rotation is saying rotate. 146 146 00:08:17,660 --> 00:08:19,720 So not saying anything about where to be on the screen. 147 147 00:08:19,720 --> 00:08:23,606 However, the position that we've got off the top is saying on the very first frame 148 148 00:08:23,606 --> 00:08:25,765 I want you to be whatever this is, 0.48. 149 149 00:08:25,765 --> 00:08:30,980 And as we scroll through it's saying I want you now to be at 0.6788. 150 150 00:08:30,980 --> 00:08:32,370 So, what do we do about that? 151 151 00:08:32,370 --> 00:08:37,130 How can we move this once we've created our positional animation. 152 152 00:08:37,130 --> 00:08:41,350 Well, there's a little technique that took me forever to find while I was trying to 153 153 00:08:41,350 --> 00:08:42,290 debug this for you. 154 154 00:08:42,290 --> 00:08:47,150 If you click on Curves while we've got your position selected 155 155 00:08:47,150 --> 00:08:50,050 to the left here, see how there's this white line? 156 156 00:08:50,050 --> 00:08:54,460 If you drag that, that will allow you to drag every single one of your key frames 157 157 00:08:54,460 --> 00:08:57,530 up or down on that particular parameter or that particular axis. 158 158 00:08:57,530 --> 00:09:00,450 So at the moment, we're exchanging the y position. 159 159 00:09:00,450 --> 00:09:04,770 If I was to click on x, then it would move it left and right. 160 160 00:09:04,770 --> 00:09:06,590 So super handy to know, so 161 161 00:09:06,590 --> 00:09:09,400 let's find where we want our animation to be starting. 162 162 00:09:09,400 --> 00:09:12,930 Just there, if we scrub through it goes up and then down. 163 163 00:09:12,930 --> 00:09:16,160 Okay, it still looks like it's going a bit too high. 164 164 00:09:16,160 --> 00:09:19,510 Basically, I don't want it overlapping the top square cuz then we'll get weird 165 165 00:09:19,510 --> 00:09:22,200 overlapping issues that we don't really wanna deal with at the moment. 166 166 00:09:22,200 --> 00:09:28,530 So let's drag the whole thing down and a little bit to there, bang, and bang. 167 167 00:09:28,530 --> 00:09:29,950 Yeah, it looks pretty good. 168 168 00:09:29,950 --> 00:09:33,350 Could probably make this whole star a little bit smaller, 169 169 00:09:33,350 --> 00:09:34,790 so I can do that naturally. 170 170 00:09:34,790 --> 00:09:37,030 I don't have to do that with animate that with a key frame. 171 171 00:09:37,030 --> 00:09:41,470 I'll just click on my Scale tool, make it a little bit smaller, and 172 172 00:09:41,470 --> 00:09:45,270 now it will retain that, yeah, that's cool. 173 173 00:09:45,270 --> 00:09:48,549 Cuz it's changing the position, that's what's being animated, okay, 174 174 00:09:48,549 --> 00:09:49,830 up to the top there. 175 175 00:09:49,830 --> 00:09:52,580 And maybe I'll, how's that look everyone? 176 176 00:09:52,580 --> 00:09:56,040 Let's see, just have a little look see at that, make sure it looks okay, 177 177 00:09:56,040 --> 00:09:59,590 we don't want the star now to be, yeah, and bam. 178 178 00:09:59,590 --> 00:10:02,090 Okay, yeah, I'm pretty happy with that. 179 179 00:10:02,090 --> 00:10:05,200 Okay, so click on Trophy, apply that to the prefab. 180 180 00:10:05,200 --> 00:10:08,700 As a final tweak I'm gonna bring it up a tiny bit bigger. 181 181 00:10:08,700 --> 00:10:10,040 Yeah, so it looks a little bit more natural. 182 182 00:10:10,040 --> 00:10:13,290 I want it to look like it's slamming down, slam slam. 183 183 00:10:13,290 --> 00:10:15,930 Okay, good, all done, excellent, okay, great stuff. 184 184 00:10:15,930 --> 00:10:19,260 So we can now place our defenders, we can choose the defender and place them. 185 185 00:10:19,260 --> 00:10:21,360 Next up we need to start our resource system so 186 186 00:10:21,360 --> 00:10:24,770 that our defenders cost points, and that we can start seeing whether 187 187 00:10:24,770 --> 00:10:26,700 you have enough points to place these things down or not. 188 188 00:10:26,700 --> 00:10:28,550 So great stuff, I'll see you in the next video. 19526

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