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
€95.85
List Price:  €134.19
You save:  €38.34
£79.54
List Price:  £111.35
You save:  £31.81
CA$143.73
List Price:  CA$201.23
You save:  CA$57.50
A$159.93
List Price:  A$223.91
You save:  A$63.97
S$135.54
List Price:  S$189.77
You save:  S$54.22
HK$777.83
List Price:  HK$1,089
You save:  HK$311.16
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,131.88
List Price:  NOK kr1,584.68
You save:  NOK kr452.80
DKK kr715.08
List Price:  DKK kr1,001.15
You save:  DKK kr286.06
NZ$176.75
List Price:  NZ$247.46
You save:  NZ$70.70
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,945.33
List Price:  ৳16,723.94
You save:  ৳4,778.61
₹8,493.77
List Price:  ₹11,891.62
You save:  ₹3,397.85
RM450.75
List Price:  RM631.07
You save:  RM180.32
₦154,938.50
List Price:  ₦216,920.10
You save:  ₦61,981.60
₨27,824.38
List Price:  ₨38,955.25
You save:  ₨11,130.86
฿3,419.79
List Price:  ฿4,787.84
You save:  ฿1,368.05
₺3,519.01
List Price:  ₺4,926.76
You save:  ₺1,407.74
B$608.53
List Price:  B$851.97
You save:  B$243.44
R1,830.80
List Price:  R2,563.19
You save:  R732.39
Лв187.32
List Price:  Лв262.25
You save:  Лв74.93
₩144,627.53
List Price:  ₩202,484.33
You save:  ₩57,856.80
₪365.39
List Price:  ₪511.57
You save:  ₪146.17
₱5,882.91
List Price:  ₱8,236.31
You save:  ₱2,353.40
¥15,643.93
List Price:  ¥21,902.13
You save:  ¥6,258.20
MX$2,007.58
List Price:  MX$2,810.70
You save:  MX$803.11
QR364.41
List Price:  QR510.19
You save:  QR145.78
P1,381.63
List Price:  P1,934.33
You save:  P552.70
KSh12,923.70
List Price:  KSh18,093.70
You save:  KSh5,170
E£5,087.81
List Price:  E£7,123.14
You save:  E£2,035.32
ብር12,764.56
List Price:  ብር17,870.89
You save:  ብር5,106.33
Kz91,790.82
List Price:  Kz128,510.82
You save:  Kz36,720
CLP$98,905.10
List Price:  CLP$138,471.10
You save:  CLP$39,566
CN¥729.56
List Price:  CN¥1,021.42
You save:  CN¥291.85
RD$6,087.13
List Price:  RD$8,522.23
You save:  RD$2,435.09
DA13,485.25
List Price:  DA18,879.89
You save:  DA5,394.64
FJ$231.62
List Price:  FJ$324.28
You save:  FJ$92.66
Q770.23
List Price:  Q1,078.35
You save:  Q308.12
GY$20,913.67
List Price:  GY$29,279.97
You save:  GY$8,366.30
ISK kr13,911.60
List Price:  ISK kr19,476.80
You save:  ISK kr5,565.20
DH1,006.07
List Price:  DH1,408.53
You save:  DH402.46
L1,836.70
List Price:  L2,571.46
You save:  L734.75
ден5,900.06
List Price:  ден8,260.33
You save:  ден2,360.26
MOP$800.26
List Price:  MOP$1,120.39
You save:  MOP$320.13
N$1,840.36
List Price:  N$2,576.58
You save:  N$736.22
C$3,678.42
List Price:  C$5,149.94
You save:  C$1,471.51
रु13,597.49
List Price:  रु19,037.04
You save:  रु5,439.54
S/372.23
List Price:  S/521.13
You save:  S/148.90
K405.36
List Price:  K567.52
You save:  K162.16
SAR375.62
List Price:  SAR525.88
You save:  SAR150.26
ZK2,766.46
List Price:  ZK3,873.15
You save:  ZK1,106.69
L477.10
List Price:  L667.96
You save:  L190.86
Kč2,408.98
List Price:  Kč3,372.68
You save:  Kč963.69
Ft39,689.03
List Price:  Ft55,566.23
You save:  Ft15,877.20
SEK kr1,103.13
List Price:  SEK kr1,544.43
You save:  SEK kr441.30
ARS$102,160.40
List Price:  ARS$143,028.65
You save:  ARS$40,868.24
Bs690.76
List Price:  Bs967.10
You save:  Bs276.33
COP$435,928.80
List Price:  COP$610,317.76
You save:  COP$174,388.96
₡50,434.81
List Price:  ₡70,610.75
You save:  ₡20,175.94
L2,537.51
List Price:  L3,552.62
You save:  L1,015.10
₲779,455.88
List Price:  ₲1,091,269.42
You save:  ₲311,813.53
$U4,474.38
List Price:  $U6,264.31
You save:  $U1,789.93
zł408.66
List Price:  zł572.14
You save:  zł163.48
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.