In this lecture, we're adding some coins that spin around, have a bit of animation, and when we drop
onto them, we can pick them up.
So let's work on our pickups.
I'll be working in level two for this exercise and something I just noticed a little bit messy.
We've got all these enemies hanging around, so I'm going to right click Create Empty.
I'll call this enemies as just an empty game object, reset the transform and then grab all the goobers
and shove them under the enemies game object.
That should be okay.
I can't see any issues there.
Famous last words.
Now if you jump into your sprites folder, there should be the coins that we downloaded.
When we downloaded all the sprites.
And you can see if we click on the Sprite editor, they've all been chopped up already.
That's good.
They look like they're chopped up in the right kind of way.
So now we're right click create an empty I'm going to call this pick ups just because there might be
a bunch of different pick ups, right click reset transform.
Then underneath here, right click, create empty.
I will call this coin.
Now for coin we need to add a bunch of components.
Let's do this nice and fast will add a sprite renderer and we pick one of our sprites.
So we'll go and pick one of the coins.
That one there looks pretty good.
What if it was coin zero?
So we've got some visualization.
We can't see it because it's all the way underneath something.
So let's have a look at our sorting layers from default.
We'll put on interactive tiles because that's what this is similar to our portal.
It's an interactive will.
We also need to change the layer to be an interactive.
Well, that's great, except we need to add a collider.
I'll add a let's say.
Collider What should we add a circle?
Collider I think because it's kind of circle in shape.
Scroll right in.
I'm going to click on my edit shape.
Just make it the appropriate size wrapped around there.
We'll make this a trigger so that we can tap it and trigger it, and that should be pretty good for
that next step.
What we want to do is deal with the animation.
So we've got our spinny spinny thing here.
Add a component, animator and animator component.
When we do these things now let's find our sprites.
I'm going to select all of them.
Select, select, select, group, select.
Did I get them all?
Yes, I think I did.
Right click create animation and we'll call this coin spin animation will drag coin spin animation into
the animations folder.
We also need an animator controller.
So I'm going to right click in here, create a animator controller.
The animator controller will call, let's see, coin coins coin, probably coin because we're spinning
one at a time aren't we, coin.
And if I click on this coin animated controller, open up our animator, you can see there's not much
going on here at the moment.
Scrolling a little bit, I'm going to drag my coin spin just into the middle.
So we'll go straight from entry to coin spin.
That's cool.
We don't need to worry about transitions.
It's going to go straight into there to hang around.
Click on Coin Spin.
Just make sure we don't forget loop time because we want it to keep going and going.
That should be the foundations of it.
The last thing we need to do is click on the coin itself and to set up what we need to connect the animator
to the animated controller.
So we look for the controller, click our selector and select on coin.
Let's click on play and see if it's actually doing what it's supposed to do with it.
Spinning.
Yes, it is.
Mission accomplished.
We can't pick it up yet though, so let's work on that next.
So I'm going to jump into scripts, make ourselves a new script, right click, create C-sharp script.
I'll call this coin pickup pickup because other pickups might behave differently to our coin pick up.
So we'll call it coin pick up.
But in the future, maybe we just have all pick ups that give you points and stuff and we just need
the one pick up script.
But for now, I'll call it coin pick up just because I'm not exactly sure what we're doing down the
track.
Going to get rid of start and update.
I don't think I'm going to need those, but what I do need is to give you a challenge, and that is
to pick up the coin.
When the player touches the coin, destroy the coin so that it disappears and make sure that it's only
the player who can pick that coin up.
There's a challenge.
Pause video.
See you back here when you've done.
Okay.
So let's have a look at what we need to do.
Well, we need to do something to do with a trigger.
So on trigger enter to DH looks pretty good.
Get rid of the private and tidy up.
Now parentheses out Kelly braces.
Now, if what?
We just did this last lecture, didn't we?
If other dot tag equals equals player.
That's right, player, then we need to do something pretty simple.
We need to just destroy the game object.
So destroy me.
The thing that I'm on, which is the coin.
So we'll save that back over into unity and you know, we'll put a couple of other coins in there just
to make sure it's not a fluke that we did one.
And by doing that, it's reminded me we need to prefab our coins.
So this is great.
I'm just going to change my size in here by holding down control and mouse wheel or just grabbing that
selector and drag coin down into the prefab folder and then drag a couple more of those into the world.
Click on play.
Let's see if we've forgotten some sort of collision related thing or if we're good here.
So full.
Yes.
No, we're not picking it up.
So let's have a look at there.
It might be a layer issue.
Let's have a look at our edit and project settings and.
It's colliding with everything at the moment.
I don't think that's a good thing.
So interactive is just with the player.
I think that'll fix it.
But no, you never know.
We'll see.
And X out of that click on play now we'll see if we can drop down.
The player is colliding we have is trigger we are a player point oh I think I've just figured it out.
Bonus points.
If you can figure out what I've done wrong, just yell it at the screen really loud so your neighbors
hear it.
Rick has forgotten to do what?
He's forgotten to put the script on the game object.
Nice work, Rick.
Add component coin, pick up script, and then we will scroll all the way up to the top and apply all.
So that will go back to the prefab.
And you know, the other thing that I didn't do that I just realized then is this is the reason that
we work in the prefab is that I just noticed I haven't tagged my player as player, so that's a little
bit sloppy on my part.
Now I'm going to override a play also.
Now if I click on my player prefab, that should all be tagged as player.
So that's why we work in the prefab.
That's why we apply back to the prefab regularly.
That's why we all look a little bit foolish when we don't do these things.
Hopefully now everything is working.
If we drop down onto the coin, it knows that we're the player and it knows that it disappears.
Excellent.
There we go.
With a little bit of messing around.
We've got our coin to work.
The moral of the story is make sure you apply everything back to your prefab or work directly into your
prefab.
There's more setting up to do in the next lecture to get our coins behaving with more functionality.
So I will see you shortly.