Esempio n. 1
0
    /// <summary>
    /// Use this to reenable collisions.
    /// </summary>
    /// <param name="pc">Collider to reenable collisions.</param>
    /// <returns></returns>

    /*   private IEnumerator reenableCollisions(Collider pc) {
     *     yield return new WaitForSeconds(0.3f);
     *     Physics.IgnoreCollision(col, pc, false);
     *  //   yield return null;
     * }
     */

    void OnTriggerEnter(Collider col)
    {
        GameItem other = col.transform.GetComponent <GameItem>();

        //check if the other object is a gameItem
        if (other == null)
        {
            return;
        }
        if (other.item == null)
        {
            return;
        }

        Ingredients ing    = new Ingredients(0, item.name, other.item.name);
        Recipe      result = Recipes.Cook(ing);

        //no recipe for this exists, do it via attribute
        if (result == null)
        {
            AttributeCollision(other);
            return;
        }

        Debug.Log(result._name);
        //do other stuff============================================================TO DO
        //check if the itemBank contains that item
        if (!iDatabase.ItemBank.ContainsKey(result._name))
        {
            return;
        }

        GameObject newItem = iDatabase.ItemBank[result._name];

        //instantiate the item
        Instantiate(newItem, this.transform.position, this.transform.rotation);


        //and destroy items accordingly===============================================TO DO
    }
Esempio n. 2
0
    //player has items in both hands, both items have GameItem components
    void Combine()
    {
        GameItem L = left.GetComponent <GameItem>();
        GameItem R = right.GetComponent <GameItem>();

        Debug.Log("Combining " + L.itemName + " and " + R.itemName);
        Debug.Log("Combining ID's " + L.item.ID + " and " + R.item.ID);
        //Ingredients ing = new Ingredients(0, L.itemName, R.itemName);
        //Recipe result = Recipes.Cook(ing);
        Recipe result = Recipes.Cook(L.item.ID, R.item.ID);

        if (result == null)
        {
            Debug.Log("Result is null!");
            return;
        }

        Debug.Log(result._name);
        //do other stuff=================================================TO DO

        if (!GameItem.iDatabase.ItemBank.ContainsKey(result._name))
        {
            return;
        }

        GameObject newItem = GameItem.iDatabase.ItemBank[result._name];

        //play an animation probably ================================== TO DO
        //detirmine which items to destroy
        if (L.itemName == result._item1)
        {
            if (result._dst1)
            {
                Destroy(L.gameObject);
                left = null;
            }
            if (result._dst2)
            {
                Destroy(R.gameObject);
                right = null;
            }
        }
        else
        {
            if (result._dst1)
            {
                Destroy(R.gameObject);
                right = null;
            }
            if (result._dst2)
            {
                Destroy(L.gameObject);
                left = null;
            }
        }

        //instantiate the new item and set its parent to a free hand
        if (left == null)
        {
            //Instantiate(newItem, FPL);
            GameObject actualItem = Instantiate(newItem, FPL.position, FPL.rotation);
            left = actualItem.transform;
            GameItem LI = left.GetComponent <GameItem>();
            LI.Initialize();
            LI.Interact(pc, 1);            //ignore collisions
        }
        else if (right == null)
        {
            //Instantiate(newItem, FPR);
            GameObject actualItem = Instantiate(newItem, FPR.position, FPR.rotation);
            right = actualItem.transform;
            GameItem RI = right.GetComponent <GameItem>();
            RI.Interact(pc, 1);            //ignore collisions
        }

        //set bothHands to false
        bothHands = false;
    }