To update the Pickup_Item object using collision logic, you need to do the following:
- Create a new C# script in the Scripts folder, name it ItemBehavior, and then drag it into the Health_Pickup object:
- Any script that uses collision detection MUST be attached to a GameObject with a Collider component, even if it's the child of a prefab.
- Create an empty GameObject, named Item:
- Make the Health_Pickup object and the Particle System object its children.
- Drag Item into the Prefabs folder:
- Replace the default code in ItemBehavior with the following, and then save it:
public class ItemBehavior : MonoBehaviour
{
// 1
void OnCollisionEnter(Collision collision)
{
// 2
if(collision.gameObject.name == "Player")
{
// 3
Destroy(this.transform.parent.gameObject);
// 4
...