Beispiel #1
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "food")
        {
            FoodController collController = coll.gameObject.GetComponent <FoodController>();
            food += collController.GetFood() * foodMultiplier;

            collController.DestroyModel();
        }
    }
Beispiel #2
0
    private void OnContact(FoodController food)
    {
        try
        {
            model.nutrition -= (-model.herb / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment + (float)model.ouputs[2] * .5f;
            model.nutrition += (-model.herb / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment + (float)model.ouputs[2] * .5f;
        }
        catch (ArgumentOutOfRangeException)
        {
            Vector3 location = transform.position;
            transform.position = new Vector3(UnityEngine.Random.Range(location.x - 5, location.x + 5), UnityEngine.Random.Range(location.y - 5, location.y + 5));
            return;
        }
        if (model.foodPref == FoodType.Herb)
        {
            if (food.Model.type == FoodType.Herb)
            {
                model.nutrition += (model.herb / 10 * .5f + .5f) * Time.deltaTime * 2 * gameController.nutritionAdjustment - (float)model.ouputs[2] * .5f;
            }
            else if (food.Model.type == FoodType.Omni)
            {
                model.nutrition += (model.omni / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment - (float)model.ouputs[2] * .3f;
            }
            else
            {
                model.nutrition -= (-model.carni / 10 * .5f + .5f) * Time.deltaTime * 2 * gameController.nutritionAdjustment + (float)model.ouputs[2] * .5f;
            }
        }
        else if (model.foodPref == FoodType.Omni)
        {
            if (food.Model.type == FoodType.Herb)
            {
                model.nutrition -= (-model.herb / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment + (float)model.ouputs[2] * .5f;
            }
            else if (food.Model.type == FoodType.Omni)
            {
                model.nutrition += (model.omni / 10 * .5f + .5f) * Time.deltaTime * 2 * gameController.nutritionAdjustment - (float)model.ouputs[2] * .5f;
            }
            else
            {
                model.nutrition += (model.carni / 10 * .5f + .5f) * Time.deltaTime * .5f * gameController.nutritionAdjustment - (float)model.ouputs[2] * .5f;
            }
        }

        else if (model.foodPref == FoodType.Carni)
        {
            if (food.Model.type == FoodType.Herb)
            {
                model.nutrition -= (-model.herb / 10 * .5f + .5f) * Time.deltaTime * 2 * gameController.nutritionAdjustment + (float)model.ouputs[2] * .5f;
            }
            else if (food.Model.type == FoodType.Omni)
            {
                model.nutrition -= (-model.omni / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment - (float)model.ouputs[2] * .5f;
            }
            else
            {
                model.nutrition += (model.carni / 10 * .5f + .5f) * Time.deltaTime * gameController.nutritionAdjustment - (float)model.ouputs[2] * .5f;
            }
        }

        food.DestroyModel();
    }