Combining Objects

So, I’m new to Unity and c# so I’m not the greatest, but willing to learn.

I’m trying to make a simple script so when you put two objects together, the create something new. For example, a bottle of water and an ingredient makes a potion.

I need a way to create a new object (the potion in this case) and delete the two ingredients. So far, I have this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Brew1 : MonoBehaviour {


    void OnCollisionEnter(Collision col)
    {
        if(col.gameObject.name == "ing_sphere")
        {
            Destroy(col.gameObject);
            Destroy(gameObject);
        }
    }
}

Which does what I want it to, except for creating the new object. I’ve tried messing around with Instantiate and I can’t seem to get it to summon a new object from the project files. How would I get it to summon a new object after deleting the first two?

Thanks in advance.

You should be able to use Instantiate to make your new GameObject appear. Do you have a prefab of your third GameObject? If so, you would need to have a reference to it on your script.

Add this public variable to the top of your script:

public GameObject newItemPrefab; //Or what ever name you want

Then assign it a value by dragging a prefab from your assets folder onto the slot in the inspector of your GameObject.

Then you can call Instantiate after collision and your tag check:

Instantiate(newItemPrefab, transform.position, transform.rotation);

By the way, ing_sphere is just a test ingredient I’m messing around with