Grouping Prefabs

10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€94.09
List Price:  €131.73
You save:  €37.64
£80.33
List Price:  £112.47
You save:  £32.13
CA$137.95
List Price:  CA$193.14
You save:  CA$55.18
A$155.90
List Price:  A$218.27
You save:  A$62.36
S$136.45
List Price:  S$191.03
You save:  S$54.58
HK$783.08
List Price:  HK$1,096.34
You save:  HK$313.26
CHF 91.31
List Price:  CHF 127.84
You save:  CHF 36.52
NOK kr1,099.13
List Price:  NOK kr1,538.83
You save:  NOK kr439.69
DKK kr702.04
List Price:  DKK kr982.89
You save:  DKK kr280.84
NZ$169.94
List Price:  NZ$237.92
You save:  NZ$67.98
د.إ367.20
List Price:  د.إ514.10
You save:  د.إ146.89
৳10,968.60
List Price:  ৳15,356.49
You save:  ৳4,387.88
₹8,361.11
List Price:  ₹11,705.89
You save:  ₹3,344.78
RM479.15
List Price:  RM670.83
You save:  RM191.68
₦120,104.65
List Price:  ₦168,151.32
You save:  ₦48,046.66
₨27,798.84
List Price:  ₨38,919.49
You save:  ₨11,120.65
฿3,667.03
List Price:  ฿5,133.99
You save:  ฿1,466.96
₺3,248.77
List Price:  ₺4,548.41
You save:  ₺1,299.64
B$518.45
List Price:  B$725.86
You save:  B$207.40
R1,905.92
List Price:  R2,668.37
You save:  R762.44
Лв184.07
List Price:  Лв257.70
You save:  Лв73.63
₩139,257.60
List Price:  ₩194,966.22
You save:  ₩55,708.61
₪377.23
List Price:  ₪528.13
You save:  ₪150.90
₱5,695.28
List Price:  ₱7,973.62
You save:  ₱2,278.34
¥15,458.12
List Price:  ¥21,641.98
You save:  ¥6,183.86
MX$1,680.99
List Price:  MX$2,353.45
You save:  MX$672.46
QR365.97
List Price:  QR512.38
You save:  QR146.40
P1,384.25
List Price:  P1,938
You save:  P553.75
KSh13,148.68
List Price:  KSh18,408.68
You save:  KSh5,260
E£4,851.82
List Price:  E£6,792.74
You save:  E£1,940.92
ብር5,709.83
List Price:  ብር7,993.99
You save:  ብር2,284.16
Kz83,396.59
List Price:  Kz116,758.56
You save:  Kz33,361.97
CLP$97,269.27
List Price:  CLP$136,180.87
You save:  CLP$38,911.60
CN¥723.78
List Price:  CN¥1,013.33
You save:  CN¥289.54
RD$5,930.22
List Price:  RD$8,302.55
You save:  RD$2,372.32
DA13,484.73
List Price:  DA18,879.17
You save:  DA5,394.43
FJ$227.82
List Price:  FJ$318.96
You save:  FJ$91.14
Q778.21
List Price:  Q1,089.53
You save:  Q311.31
GY$20,908.09
List Price:  GY$29,272.17
You save:  GY$8,364.07
ISK kr14,179.58
List Price:  ISK kr19,851.98
You save:  ISK kr5,672.40
DH1,015.88
List Price:  DH1,422.27
You save:  DH406.39
L1,779.82
List Price:  L2,491.82
You save:  L712
ден5,791.90
List Price:  ден8,108.89
You save:  ден2,316.99
MOP$805.91
List Price:  MOP$1,128.31
You save:  MOP$322.39
N$1,902.84
List Price:  N$2,664.06
You save:  N$761.21
C$3,694.12
List Price:  C$5,171.92
You save:  C$1,477.79
रु13,341.25
List Price:  रु18,678.28
You save:  रु5,337.03
S/371.93
List Price:  S/520.72
You save:  S/148.78
K379.86
List Price:  K531.82
You save:  K151.96
SAR375.07
List Price:  SAR525.11
You save:  SAR150.04
ZK2,516.51
List Price:  ZK3,523.21
You save:  ZK1,006.70
L468.24
List Price:  L655.55
You save:  L187.31
Kč2,375.47
List Price:  Kč3,325.75
You save:  Kč950.28
Ft37,163.97
List Price:  Ft52,031.05
You save:  Ft14,867.07
SEK kr1,095.61
List Price:  SEK kr1,533.90
You save:  SEK kr438.29
ARS$86,820.40
List Price:  ARS$121,552.04
You save:  ARS$34,731.63
Bs693.54
List Price:  Bs970.99
You save:  Bs277.44
COP$387,000.37
List Price:  COP$541,816
You save:  COP$154,815.63
₡50,265.75
List Price:  ₡70,374.06
You save:  ₡20,108.31
L2,477.69
List Price:  L3,468.86
You save:  L991.17
₲740,341.68
List Price:  ₲1,036,507.98
You save:  ₲296,166.29
$U3,889.78
List Price:  $U5,445.86
You save:  $U1,556.07
zł407.99
List Price:  zł571.20
You save:  zł163.21
Already have an account? Log In

Transcript

Okay, so I've deleted all the triangles out of this scene, and I'm just going to drag the triangle back into the scene. So you'll see here that the triangles at 00, point two, seven and zero. So you can see, I think it was before it was a little bit low. So I'll just bring it up to 0.27 might be different for your, your project, but just make sure it's like sitting flush with the ground just so it looks nice. And so we have the triangle right here. And let's just bring it forward a little bit.

And let's turn our play back on. And let's see what happens when the player runs into it. Okay, the play goes straight through as not good. So what we want to do is we need to look at the triangle and see what's on our trial. So we've got our mesh filter, we got a mesh renderer on which renders it to the screen. And we basically that's basically it, we don't have anything else.

So what we want to do is we want to add a mesh collider so you can just type in mesh colada, you could use Say for example, square kilometer if you wanted things to be a little bit simple um, but this should be pretty good because it's certainly a triangle. So then if we press play now you'll see what will happen. Cool, our player goes over the top. That's pretty awesome. So because our world is always flat, we never ever want our player to be able to move up or down. So you can actually go over to our player, go down to rigidbody, we can open up constraints, and we can actually freeze position on the y axis.

Press play again. And you'll see it's just rotating in spot there because it can't move up and over. And that's exactly what we want. Fantastic. So now we have a triangle. Well, how do we use them to create randomness?

How do we use them to create the game that you guys saw at the beginning, the game the finished the finished project? Well, we need to actually create a few different pre-fabs a few different instances. So we have a generic triangle here, that just is all great. But we need to actually create like sets of triangles like a grouping of triangles and then use them as prefabs. So how we're going to do that is let's turn off our player again. And let's turn our triangle.

Let's bring a triangle back to zero in the z axis, so it's right in the middle. Let's just bring it here. Just like to position the camera a bit better. So we can see what was going on. And let's get a triangle. And let's copy it and paste it.

And we're going to put this one at position two, and we're going to put this one at position negative two. So then we've got a gap through the middle. Awesome. So then we also want to create an empty and we want to make make sure you zero this empty out. 000 and we can call this triangles underscore a. And we can grab these two triangles, which if they're at the perfect position, drag these two triangles into triangles a triangle, a should be at 000 for everything, and then we should have negative two, then two.

And then we'll be able to actually drag this, you know, we can drag this forward and back. You can do whatever you want with it, you can move it off to the side, but now it's grouped together. Well, that's awesome. But we also but what else do we need? So we need Okay, so we've got the two colliders here. So that's all great.

And we want to actually tag these triangles with a special tag. So when we run into them, we can actually, you know, create a game over screen. So if we click on one of the triangles, and we go up here, and we click on the tag, and we click open tag, we click the tag button here and click Add tag. We can have a list of tags here, we can click the Add button and we can call it triangle with a lowercase t, triangle. And then we can go over to our two triangles, and we can set their tag to triangle. We can go to a prefab we can set that tag to triangle.

And so now whenever we run into it, we can actually access this through code. And we can ask the question, Hey, have you run into something with the tag triangle, and then we can use that to form our game logic. So the only other thing we need to do is we need to create a center section. So the center section will be where we get the score. And we just want to make sure so whenever the player passes through the center section, he gets one or she or he gets one point. So what we can do is we can create a new 3d object create a new we can actually let's create a new empty let's grab this empty 00 Zero make sure it's absolute center, we can call this gap.

We can drag this gap on to triangle day. Once again triangles, they should be at 00. And all these should be negative two on the x two on the X and 000. So it's right in the middle. Then all we need to do is add a box Collider. And you can see here I'm not sure if you can see because it's also green.

But you can see here we've got a, we have a box Collider. Now all we need to do is click is, is trigger. And then let's see what happens. So if the player runs into the section, that's fine, but it still can go through the center. The reason it can go through the center is because we've turned his trigger on if we didn't turn his trigger on. The collider would act like a colada.

Bam, we ran into the colada, but because we've turned his trigger on, we can pass right through it. So we'll use another separate line of code to say, are we in the Trigger Zone gap. And if we are, give it a point. And so that's how we'll form our game logic. And the only thing we want to do is we want to add a tag to this gap section. So we can go over to the tag section, add tag and added a tag and we can call call it call pump.

Cool. And then make sure you assign it to score up. And then all we need to do is we need to make sure this is at zero is we can just drag this whole parent object here into the prefab section. And then we have our own. We can get rid of it now and then whenever we drag it in, we have our own prefab sort of area that will give us a score and we can run into These two enemies we don't have any of the logic coded in yet, but this is how we how we will be going forward with the prefabs. So we've created one prefab, but we actually need to create two more prefabs.

And I'm pretty sure you guys will guess how we're going to do it. Let's just do it really quickly copy paste, and we can paste it again, let's open up the triangle, so we got one at negative two. Let's add this make make this one zero. Let's turn off this one, sorry and turn off this one just so it looks so you can see what's going on. And we need to make our gap at two. So then let's turn off our player as well.

So then we have a situation where we have the two triangles on the left hand side and we have the cube here, so that's fantastic. We can call this triangles B. Drag this in. Done. Now we can get rid of this Get rid of this. And we can do the same thing here, turn it back on, we can go triangles at two, triangle at zero.

And we can make the gap. Make it two. And then we can call it triangles. See. Awesome. So then if we delete this, you'll be able to see if we drag this in, and then we drag this in and then we drag this in.

Make sure these tend to play back on. We can press play, and the player can move through these sections. We need to make sure that all of the gaps, let's just go to gap is trigger gap is trigger. And gap is trigger, press play. Man we can pass through, and everything works fine. Cool.

So we got a basic scenario here. So let's just, I'll just drag this up. So we got a BC. Let's put this one at, say, let's put a 20 on the Z. Let's put B at 40. And let's put C at 60.

So if we press play, let's see what it looks like. Cool, so would you get a score there? We get a school there. And we get a school day unless we bumped into them. So So in the next episode, we'll be coding the functionality of these gaps in these triangles. What happens when you run into a gap where we want the score to go up.

So in the next episode we'll be coding the logic or the functionality behind the prefabs that we just created. See you there

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.