private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.CompareTag("Stick"))
        {
            Stick_Content c = collision.collider.GetComponent <Stick_Content>();
            for (int i = 0; i < c.ingredientsPivots.Length; i++)
            {
                for (int j = 0; j < pools.Length; j++)
                {
                    if (c.ingredientsPivots[i] != null)
                    {
                        if (snacksList.Contains(collision.transform))
                        {
                            snacksList.Remove(collision.transform);
                        }
                        pools[i].ReturnObjectToPool(c.ingredientsPivots[i].gameObject);
                    }
                }
            }
        }
        else
        {
            if (collision.rigidbody != null && snacksList.Contains(collision.rigidbody.transform))
            {
                snacksList.Remove(collision.rigidbody.transform);
            }

            for (int i = 0; i < pools.Length; i++)
            {
                pools[i].ReturnObjectToPool(collision.gameObject);
            }
        }
    }
Beispiel #2
0
    private void DropObject()
    {
        Rigidbody objRB = grabObject.GetComponent <Rigidbody>();

        objRB.isKinematic = false;
        objRB.transform.SetParent(objRB.GetComponent <Poolable>().pool.transform);
        isGrabbing = false;
        withStick  = false;
        grabObject = null;

        if (stick != null)
        {
            stick.Release();
            stick = null;
        }
    }
    void SelectNewTarget()
    {
        food  = null;
        stick = null;

        int id = Random.Range(0, grill.objectsOnGrill.Count);

        target = grill.objectsOnGrill[id].transform;

        step = 1 / stealDuration;
        lastTargetPosition = target.position;
        transform.forward  = target.position - transform.position;
        food = target.GetComponent <Food>();

        if (food == null)
        {
            stick = target.GetComponent <Stick_Content>();
        }
    }
    private bool CheckIfRightCombination(Stick_Content stick)
    {
        //First check if the order is right
        if (Gameplay_Manager.Instance.orders.TakeOrder(stick.currentOrder.order))
        {
            int points = 0;

            //Then check if the ingredients are not burnt
            foreach (Food food in stick.foods)
            {
                if (food.currentStage == Food.stage.WellDone)
                {
                    points++;
                }
            }

            if (points == stick.foods.Count)
            {
                return(true);
            }
        }

        return(false);
    }
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Stick"))
     {
         Stick_Content c = other.GetComponent <Stick_Content>();
         for (int i = 0; i < c.ingredientsPivots.Length; i++)
         {
             for (int j = 0; j < pools.Length; j++)
             {
                 if (c.ingredientsPivots[i] != null)
                 {
                     pools[i].ReturnObjectToPool(c.ingredientsPivots[i].gameObject);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < pools.Length; i++)
         {
             pools[i].ReturnObjectToPool(other.gameObject);
         }
     }
 }
    private void OnCollisionEnter(Collision other)
    {
        //Stick with multipple ingredients
        if (other.gameObject.CompareTag("Stick"))
        {
            Stick_Content stick = other.gameObject.GetComponent <Stick_Content>();

            if (CheckIfRightCombination(stick))
            {
                Debug.Log("Correct!");
                GlobalGame_Manager.Instance.AddPoints(correctPoints);
            }
            else
            {
                Debug.Log("Incorrect...");
                GlobalGame_Manager.Instance.AddPoints(wrongPoints);
                Gameplay_Manager.Instance.orders.AddWrong();
            }

            //Clear the ingredients
            stick.ReturnFoodsToPool();

            //Return the Stick
            ObjectPool[] pools = Gameplay_Manager.Instance.pools;
            for (int i = 0; i < pools.Length; i++)
            {
                if (pools[i].ReturnObjectToPool(other.gameObject))
                {
                    break;
                }
            }

            //Clear the order
            stick.currentOrder.order.ingredients.Clear();
        }
        else if (other.gameObject.CompareTag("Ingredient"))         //Single Ingredient
        {
            Order o = new Order();
            Food  f = other.collider.attachedRigidbody.GetComponent <Food>();
            o.ingredients.Add(f.ingredientImage);

            bool correct = false;

            if (Gameplay_Manager.Instance.orders.TakeOrder(o))
            {
                if (f.currentStage == Food.stage.WellDone)
                {
                    Debug.Log("Correct!");
                    GlobalGame_Manager.Instance.AddPoints(correctPoints);
                    correct = true;
                }
            }

            if (!correct)
            {
                Debug.Log("Incorrect...");
                GlobalGame_Manager.Instance.AddPoints(wrongPoints);
                Gameplay_Manager.Instance.orders.AddWrong();
            }

            //Return the Ingredient
            ObjectPool[] pools = Gameplay_Manager.Instance.pools;
            for (int i = 0; i < pools.Length; i++)
            {
                if (pools[i].ReturnObjectToPool(other.gameObject))
                {
                    break;
                }
            }
        }
    }
Beispiel #7
0
    private IEnumerator GrabObject(GameObject objectToGrab)
    {
        controller.acting = true;
        float   timePassed = 0;
        Vector3 startPos   = initPos;
        Vector3 endPos     = Vector3.up * .05f;

        endPos.y = 0;
        float duration = grabDuration / 2;

        //Down
        while (timePassed < duration)
        {
            timePassed += Time.deltaTime;

            float value = grabCurveDown.Evaluate(timePassed / duration);
            handPivot.localPosition = Vector3.LerpUnclamped(startPos, endPos, value);

            yield return(null);
        }

        //Grab
        Transform pivot = GetCorrectPivot(objectToGrab);

        ObjectPool pool = objectToGrab.GetComponent <ObjectPool>();

        if (pool != null)
        {
            objectToGrab = pool.GetPooledObject(false);
            objectToGrab.GetComponent <Poolable>().pool = pool;
        }

        stick = objectToGrab.GetComponent <Stick_Content>();
        if (stick != null)
        {
            stick.Grab();
            objectToGrab.transform.localRotation = pivot.rotation;
            Sound_Manager.Instance.PlayRandomSFX(Sound_Manager.Instance.audioHolder.pickingUpOther.simple);
        }
        else
        {
            objectToGrab.transform.localRotation = Quaternion.Euler(Random.insideUnitSphere * 360f);
            Sound_Manager.Instance.PlayRandomSFX(objectToGrab.GetComponent <Food>().grabClips);
        }

        grabObject = objectToGrab;
        Rigidbody objectRB = grabObject.GetComponent <Rigidbody>();

        objectRB.isKinematic        = true;
        objectRB.transform.position = pivot.position;
        objectRB.transform.SetParent(pivot);
        isGrabbing = true;
        grill.RemoveFromGrill(objectRB.GetComponent <Cookable>());

        //Up
        timePassed = 0;
        startPos   = endPos;
        endPos     = initPos;

        while (timePassed < duration)
        {
            timePassed += Time.deltaTime;

            float value = grabCurveUp.Evaluate(timePassed / duration);
            handPivot.localPosition = Vector3.LerpUnclamped(startPos, endPos, value);

            yield return(null);
        }

        handPivot.localPosition = endPos;
        controller.acting       = false;
        finishedGrabbing        = true;
    }