Basic Item Pickups In Unity

Ben Pielstick
May 20, 2021

Having a player character pick up items is pretty straightforward. Apart from the visualization aspect, all you really need is a trigger and a few lines of C# script.

Whatever we’re picking up needs a collider set to Is Trigger, and a Rigidbody component so that it can listen for collisions
In our script we can do something like this, where we listen for trigger enter, check if whatever entered was a player, then give the player the pickup item and delete the game object
Over in our player script we take whatever it was we picked up, and handle it any way we want. In this case we’re simply counting up the coins and passing the new coin total off to the UI

That’s really all there is to it. You could of course do any number of other things when an item is picked up, which is what makes Unity so easy to work with.

--

--

Ben Pielstick

Game developer with over 12 years of experience, mainly focused on MMOs.