It is often a basic game requirement for the player to pick up the item. Picking up items is also followed by an increase in score. In this Tech-Recipe we will show you how the player can Pick Objects in Unity.
For starters, i recommend you start with games like Roll a Ball. Unity has a whole course on it. You can go check it out. In this Tech-Recipe we will cover two things. In the first part, we will put enough game together to have a player and a pick-up item. Later we will write a simple script and attach to the item.
First thing first, read our previous Tech-Recipe to find out how to move the play around the environment once you have a mobile player you can add items for it to pick up.
In the game you obviously do not want a single item to be picked up by the player. So, you can prepare the pickup item. Complete its behavior by adding a rigid body component. You have to add colliders to both colliding bodies. After attaching the script, you can make it a prefab and later add it to the scene.
A prefab is a very useful property in unity. Unity’s Prefab system allows you to create, configure, and store a GameObject complete with all its components, property values, and child GameObjects as a reusable asset. The Prefab Asset acts as a template from which you can create new Prefab instances in the Scene
How to Pick Objects in Unity
Step-by-Step Procedure.
1. We have already done a tech-recipe on movement of the player. Make sure you have a mobile player in your game.
2. Now that you have a player, you can move it around to pick the objects.
3. To make a pickup item, add a cube, or any pickup shape item shape you want.
4. Add rigidbody and collider. Pickup colliders must be trigger, so we can walk over.
5. Attach pickup script to the player. This will also make the pickup disappear.
Check out other tech-recipes
How to Set Camera to Follow the Player in Unity | 3D Game Development
How to Add Rigidbody to a Gameobject in Unity | 3D Game Development
Detect Collision in Unity | 3D Game Development
How Can I run Unity 3d in Windows 7 64-bit?
How to Perform Simple Animation in Unity | 3D Game Development